Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
41be170
gh-109595: Add -Xcpu_count=<n> cmdline for container users
corona10 Sep 21, 2023
f7a7428
Check style
corona10 Sep 21, 2023
7009bbe
Add help
corona10 Sep 21, 2023
d1f91d8
Apply suggestions from code review
corona10 Sep 21, 2023
8c92ed6
Apply suggestions from code review
corona10 Sep 21, 2023
c27bdfc
Check style
corona10 Sep 21, 2023
b13e5ee
Address code review
corona10 Sep 21, 2023
45fce16
Address code review
corona10 Sep 21, 2023
49a48e4
Address code review
corona10 Sep 21, 2023
829a8e8
Address code review
corona10 Sep 21, 2023
cfb33a4
Fix test
corona10 Sep 21, 2023
95a2173
Update NEWS.d
corona10 Sep 21, 2023
0394d1d
Address code review
corona10 Sep 21, 2023
f4a3f01
Update
corona10 Sep 21, 2023
60a28fe
Update
corona10 Sep 21, 2023
7e5595c
nit
corona10 Sep 21, 2023
8678012
Update
corona10 Sep 21, 2023
cbc5484
Add PYTHONCPUCOUNT
corona10 Sep 21, 2023
4622b60
Add PYTHONCPUCOUNT
corona10 Sep 21, 2023
50f0178
Apply suggestions from code review
corona10 Sep 21, 2023
5c3ac68
Update Python/initconfig.c
corona10 Sep 21, 2023
a276bfd
Fix
corona10 Sep 21, 2023
9c582be
Update whatsnew
corona10 Sep 21, 2023
35b952f
nit
corona10 Sep 21, 2023
f04ea58
Check style
corona10 Sep 21, 2023
7ecf705
Fix docs
corona10 Sep 21, 2023
18dcd44
Update doc
corona10 Sep 21, 2023
b344f4f
nit
corona10 Sep 21, 2023
8069d21
Update
corona10 Sep 21, 2023
c70bc82
Update
corona10 Sep 21, 2023
c8abc29
Update
corona10 Sep 21, 2023
2ac6901
Address code review
corona10 Sep 21, 2023
f0a3ebf
Address code review
corona10 Sep 21, 2023
89d8bb2
Address Victor's suggestion
corona10 Sep 24, 2023
66c617f
nit
corona10 Sep 24, 2023
4a72ed4
Address Erlend's review
corona10 Sep 26, 2023
0426e3e
fix
corona10 Sep 26, 2023
ac5329b
Merge remote-tracking branch 'upstream/main' into gh-109595
corona10 Sep 30, 2023
e50e678
fix
corona10 Sep 30, 2023
24fe0e4
Add space
corona10 Sep 30, 2023
32843ed
Update os.py
corona10 Sep 30, 2023
a954f1c
nit
corona10 Sep 30, 2023
3ab2bc4
Add test code
corona10 Sep 30, 2023
7231697
Update docs
corona10 Sep 30, 2023
b18da0d
fix
corona10 Oct 1, 2023
3579fc4
Address code reivew
corona10 Oct 1, 2023
134ed9e
Address code review
corona10 Oct 1, 2023
2bec7f4
Add test
corona10 Oct 1, 2023
9f7cb5e
fix
corona10 Oct 1, 2023
1217ab5
fix
corona10 Oct 1, 2023
64da2f9
fix
corona10 Oct 1, 2023
64c7329
fix
corona10 Oct 1, 2023
cc54afb
Update
corona10 Oct 1, 2023
ba421c7
Address code review
corona10 Oct 1, 2023
5f20bf6
Update NEWS.d
corona10 Oct 1, 2023
c11789b
Update
corona10 Oct 1, 2023
936c182
Update
corona10 Oct 1, 2023
2f0dc1c
Address code review
corona10 Oct 1, 2023
a7b2c88
Rename to PYTHON_CPU_COUNT
corona10 Oct 1, 2023
551c76d
Hidden overrided cpu count
corona10 Oct 2, 2023
75021be
Use overridden
corona10 Oct 2, 2023
57dd53b
Minor refactoring
corona10 Oct 2, 2023
3f9da50
Revert to PYTHONCPUCOUNT
corona10 Oct 2, 2023
57e82c5
fix
corona10 Oct 2, 2023
c37c8d0
Use PYTHON_CPU_COUNT
corona10 Oct 3, 2023
c7726e5
Address Greg's review
corona10 Oct 3, 2023
de8bf53
Address Greg's code review
corona10 Oct 3, 2023
633914b
nit
corona10 Oct 3, 2023
37fbdfe
Include multiprocessing in docs, reword.
gpshead Oct 3, 2023
a0cfb21
Merge remote-tracking branch 'upstream/main' into gh-109595
corona10 Oct 3, 2023
8daa3b7
Merge remote-tracking branch 'upstream/main' into gh-109595
corona10 Oct 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into gh-109595
  • Loading branch information
corona10 committed Sep 30, 2023
commit ac5329be407a81487452a48daca5884eb268c4e9
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ os
environment variable :envvar:`PYTHONCPUCOUNT` or the new command-line option
:option:`-X cpu_count <-X>`. This option is useful for users who need to limit
CPU resources of a container system.(Contributed by Donghee Na in :gh:`109595`)
* Add :func:`os.process_cpu_count` function to get the number of logical CPUs
usable by the calling thread of the current process.
(Contributed by Victor Stinner in :gh:`109649`.)

pathlib
-------
Expand Down
310 changes: 83 additions & 227 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static const PyConfigSpec PYCONFIG_SPEC[] = {
SPEC(use_frozen_modules, UINT),
SPEC(safe_path, UINT),
SPEC(int_max_str_digits, INT),
SPEC(int_cpu_coumt, INT),
SPEC(pathconfig_warnings, UINT),
SPEC(program_name, WSTR),
SPEC(pythonpath_env, WSTR_OPT),
Expand Down Expand Up @@ -975,100 +976,45 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
{
PyConfig_Clear(config);

#define COPY_ATTR(ATTR) config->ATTR = config2->ATTR
#define COPY_WSTR_ATTR(ATTR) \
do { \
status = PyConfig_SetString(config, &config->ATTR, config2->ATTR); \
if (_PyStatus_EXCEPTION(status)) { \
return status; \
} \
} while (0)
#define COPY_WSTRLIST(LIST) \
do { \
if (_PyWideStringList_Copy(&config->LIST, &config2->LIST) < 0) { \
return _PyStatus_NO_MEMORY(); \
} \
} while (0)

COPY_ATTR(_config_init);
COPY_ATTR(isolated);
COPY_ATTR(use_environment);
COPY_ATTR(dev_mode);
COPY_ATTR(install_signal_handlers);
COPY_ATTR(use_hash_seed);
COPY_ATTR(hash_seed);
COPY_ATTR(_install_importlib);
COPY_ATTR(faulthandler);
COPY_ATTR(tracemalloc);
COPY_ATTR(perf_profiling);
COPY_ATTR(import_time);
COPY_ATTR(code_debug_ranges);
COPY_ATTR(show_ref_count);
COPY_ATTR(dump_refs);
COPY_ATTR(dump_refs_file);
COPY_ATTR(malloc_stats);

COPY_WSTR_ATTR(pycache_prefix);
COPY_WSTR_ATTR(pythonpath_env);
COPY_WSTR_ATTR(home);
COPY_WSTR_ATTR(program_name);

COPY_ATTR(parse_argv);
COPY_WSTRLIST(argv);
COPY_WSTRLIST(warnoptions);
COPY_WSTRLIST(xoptions);
COPY_WSTRLIST(module_search_paths);
COPY_ATTR(module_search_paths_set);
COPY_WSTR_ATTR(stdlib_dir);

COPY_WSTR_ATTR(executable);
COPY_WSTR_ATTR(base_executable);
COPY_WSTR_ATTR(prefix);
COPY_WSTR_ATTR(base_prefix);
COPY_WSTR_ATTR(exec_prefix);
COPY_WSTR_ATTR(base_exec_prefix);
COPY_WSTR_ATTR(platlibdir);

COPY_ATTR(site_import);
COPY_ATTR(bytes_warning);
COPY_ATTR(warn_default_encoding);
COPY_ATTR(inspect);
COPY_ATTR(interactive);
COPY_ATTR(optimization_level);
COPY_ATTR(parser_debug);
COPY_ATTR(write_bytecode);
COPY_ATTR(verbose);
COPY_ATTR(quiet);
COPY_ATTR(user_site_directory);
COPY_ATTR(configure_c_stdio);
COPY_ATTR(buffered_stdio);
COPY_WSTR_ATTR(filesystem_encoding);
COPY_WSTR_ATTR(filesystem_errors);
COPY_WSTR_ATTR(stdio_encoding);
COPY_WSTR_ATTR(stdio_errors);
#ifdef MS_WINDOWS
COPY_ATTR(legacy_windows_stdio);
#endif
COPY_ATTR(skip_source_first_line);
COPY_WSTR_ATTR(run_command);
COPY_WSTR_ATTR(run_module);
COPY_WSTR_ATTR(run_filename);
COPY_WSTR_ATTR(check_hash_pycs_mode);
COPY_ATTR(pathconfig_warnings);
COPY_ATTR(_init_main);
COPY_ATTR(use_frozen_modules);
COPY_ATTR(safe_path);
COPY_WSTRLIST(orig_argv);
COPY_ATTR(_is_python_build);
COPY_ATTR(int_max_str_digits);
COPY_ATTR(cpu_count);
#ifdef Py_STATS
COPY_ATTR(_pystats);
#endif

#undef COPY_ATTR
#undef COPY_WSTR_ATTR
#undef COPY_WSTRLIST
PyStatus status;
const PyConfigSpec *spec = PYCONFIG_SPEC;
for (; spec->name != NULL; spec++) {
char *member = (char *)config + spec->offset;
char *member2 = (char *)config2 + spec->offset;
switch (spec->type) {
case PyConfig_MEMBER_INT:
case PyConfig_MEMBER_UINT:
{
*(int*)member = *(int*)member2;
break;
}
case PyConfig_MEMBER_ULONG:
{
*(unsigned long*)member = *(unsigned long*)member2;
break;
}
case PyConfig_MEMBER_WSTR:
case PyConfig_MEMBER_WSTR_OPT:
{
const wchar_t *str = *(const wchar_t**)member2;
status = PyConfig_SetString(config, (wchar_t**)member, str);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
break;
}
case PyConfig_MEMBER_WSTR_LIST:
{
if (_PyWideStringList_Copy((PyWideStringList*)member,
(const PyWideStringList*)member2) < 0) {
return _PyStatus_NO_MEMORY();
}
break;
}
default:
Py_UNREACHABLE();
}
}
return _PyStatus_OK();
}

Expand All @@ -1081,101 +1027,45 @@ _PyConfig_AsDict(const PyConfig *config)
return NULL;
}

#define SET_ITEM(KEY, EXPR) \
do { \
PyObject *obj = (EXPR); \
if (obj == NULL) { \
goto fail; \
} \
int res = PyDict_SetItemString(dict, (KEY), obj); \
Py_DECREF(obj); \
if (res < 0) { \
goto fail; \
} \
} while (0)
#define SET_ITEM_INT(ATTR) \
SET_ITEM(#ATTR, PyLong_FromLong(config->ATTR))
#define SET_ITEM_UINT(ATTR) \
SET_ITEM(#ATTR, PyLong_FromUnsignedLong(config->ATTR))
#define FROM_WSTRING(STR) \
((STR != NULL) ? \
PyUnicode_FromWideChar(STR, -1) \
: Py_NewRef(Py_None))
#define SET_ITEM_WSTR(ATTR) \
SET_ITEM(#ATTR, FROM_WSTRING(config->ATTR))
#define SET_ITEM_WSTRLIST(LIST) \
SET_ITEM(#LIST, _PyWideStringList_AsList(&config->LIST))

SET_ITEM_INT(_config_init);
SET_ITEM_INT(isolated);
SET_ITEM_INT(use_environment);
SET_ITEM_INT(dev_mode);
SET_ITEM_INT(install_signal_handlers);
SET_ITEM_INT(use_hash_seed);
SET_ITEM_UINT(hash_seed);
SET_ITEM_INT(faulthandler);
SET_ITEM_INT(tracemalloc);
SET_ITEM_INT(perf_profiling);
SET_ITEM_INT(import_time);
SET_ITEM_INT(code_debug_ranges);
SET_ITEM_INT(show_ref_count);
SET_ITEM_INT(dump_refs);
SET_ITEM_INT(malloc_stats);
SET_ITEM_WSTR(filesystem_encoding);
SET_ITEM_WSTR(filesystem_errors);
SET_ITEM_WSTR(pycache_prefix);
SET_ITEM_WSTR(program_name);
SET_ITEM_INT(parse_argv);
SET_ITEM_WSTRLIST(argv);
SET_ITEM_WSTRLIST(xoptions);
SET_ITEM_WSTRLIST(warnoptions);
SET_ITEM_WSTR(pythonpath_env);
SET_ITEM_WSTR(home);
SET_ITEM_INT(module_search_paths_set);
SET_ITEM_WSTRLIST(module_search_paths);
SET_ITEM_WSTR(stdlib_dir);
SET_ITEM_WSTR(executable);
SET_ITEM_WSTR(base_executable);
SET_ITEM_WSTR(prefix);
SET_ITEM_WSTR(base_prefix);
SET_ITEM_WSTR(exec_prefix);
SET_ITEM_WSTR(base_exec_prefix);
SET_ITEM_WSTR(platlibdir);
SET_ITEM_INT(site_import);
SET_ITEM_INT(bytes_warning);
SET_ITEM_INT(warn_default_encoding);
SET_ITEM_INT(inspect);
SET_ITEM_INT(interactive);
SET_ITEM_INT(optimization_level);
SET_ITEM_INT(parser_debug);
SET_ITEM_INT(write_bytecode);
SET_ITEM_INT(verbose);
SET_ITEM_INT(quiet);
SET_ITEM_INT(user_site_directory);
SET_ITEM_INT(configure_c_stdio);
SET_ITEM_INT(buffered_stdio);
SET_ITEM_WSTR(stdio_encoding);
SET_ITEM_WSTR(stdio_errors);
#ifdef MS_WINDOWS
SET_ITEM_INT(legacy_windows_stdio);
#endif
SET_ITEM_INT(skip_source_first_line);
SET_ITEM_WSTR(run_command);
SET_ITEM_WSTR(run_module);
SET_ITEM_WSTR(run_filename);
SET_ITEM_INT(_install_importlib);
SET_ITEM_WSTR(check_hash_pycs_mode);
SET_ITEM_INT(pathconfig_warnings);
SET_ITEM_INT(_init_main);
SET_ITEM_WSTRLIST(orig_argv);
SET_ITEM_INT(use_frozen_modules);
SET_ITEM_INT(safe_path);
SET_ITEM_INT(_is_python_build);
SET_ITEM_INT(int_max_str_digits);
SET_ITEM_INT(cpu_count);
#ifdef Py_STATS
SET_ITEM_INT(_pystats);
#endif
const PyConfigSpec *spec = PYCONFIG_SPEC;
for (; spec->name != NULL; spec++) {
char *member = (char *)config + spec->offset;
PyObject *obj;
switch (spec->type) {
case PyConfig_MEMBER_INT:
case PyConfig_MEMBER_UINT:
{
int value = *(int*)member;
obj = PyLong_FromLong(value);
break;
}
case PyConfig_MEMBER_ULONG:
{
unsigned long value = *(unsigned long*)member;
obj = PyLong_FromUnsignedLong(value);
break;
}
case PyConfig_MEMBER_WSTR:
case PyConfig_MEMBER_WSTR_OPT:
{
const wchar_t *wstr = *(const wchar_t**)member;
if (wstr != NULL) {
obj = PyUnicode_FromWideChar(wstr, -1);
}
else {
obj = Py_NewRef(Py_None);
}
break;
}
case PyConfig_MEMBER_WSTR_LIST:
{
const PyWideStringList *list = (const PyWideStringList*)member;
obj = _PyWideStringList_AsList(list);
break;
}
default:
Py_UNREACHABLE();
}

if (obj == NULL) {
Py_DECREF(dict);
Expand Down Expand Up @@ -1438,44 +1328,10 @@ _PyConfig_FromDict(PyConfig *config, PyObject *dict)
return -1;
}

GET_UINT(pathconfig_warnings);
GET_WSTR(program_name);
GET_WSTR_OPT(pythonpath_env);
GET_WSTR_OPT(home);
GET_WSTR(platlibdir);

// Path configuration output
GET_UINT(module_search_paths_set);
GET_WSTRLIST(module_search_paths);
GET_WSTR_OPT(stdlib_dir);
GET_WSTR_OPT(executable);
GET_WSTR_OPT(base_executable);
GET_WSTR_OPT(prefix);
GET_WSTR_OPT(base_prefix);
GET_WSTR_OPT(exec_prefix);
GET_WSTR_OPT(base_exec_prefix);

GET_UINT(skip_source_first_line);
GET_WSTR_OPT(run_command);
GET_WSTR_OPT(run_module);
GET_WSTR_OPT(run_filename);

GET_UINT(_install_importlib);
GET_UINT(_init_main);
GET_UINT(use_frozen_modules);
GET_UINT(safe_path);
GET_UINT(_is_python_build);
GET_INT(int_max_str_digits);
GET_INT(cpu_count);
#ifdef Py_STATS
GET_UINT(_pystats);
#endif

#undef CHECK_VALUE
#undef GET_UINT
#undef GET_INT
#undef GET_WSTR
#undef GET_WSTR_OPT
if (config->hash_seed > MAX_HASH_SEED) {
config_dict_invalid_value("hash_seed");
return -1;
}
return 0;
}

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.