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

Skip to content

Commit ebdcd85

Browse files
committed
Move private function _args_from_interpreter_flags() to subprocess.py, so
that it can be imported when threads are disabled. (followup to issue #12098)
1 parent 77c84f2 commit ebdcd85

4 files changed

Lines changed: 38 additions & 32 deletions

File tree

Lib/multiprocessing/util.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import atexit
1515
import threading # we want threading to install it's
1616
# cleanup function before multiprocessing does
17+
from subprocess import _args_from_interpreter_flags
1718

1819
from multiprocessing.process import current_process, active_children
1920

@@ -297,32 +298,3 @@ def __init__(self):
297298
def __reduce__(self):
298299
return type(self), ()
299300

300-
#
301-
# Get options for python to produce the same sys.flags
302-
#
303-
304-
def _args_from_interpreter_flags():
305-
"""Return a list of command-line arguments reproducing the current
306-
settings in sys.flags and sys.warnoptions."""
307-
flag_opt_map = {
308-
'debug': 'd',
309-
# 'inspect': 'i',
310-
# 'interactive': 'i',
311-
'optimize': 'O',
312-
'dont_write_bytecode': 'B',
313-
'no_user_site': 's',
314-
'no_site': 'S',
315-
'ignore_environment': 'E',
316-
'verbose': 'v',
317-
'bytes_warning': 'b',
318-
'quiet': 'q',
319-
'hash_randomization': 'R',
320-
}
321-
args = []
322-
for flag, opt in flag_opt_map.items():
323-
v = getattr(sys.flags, flag)
324-
if v > 0:
325-
args.append('-' + opt * v)
326-
for opt in sys.warnoptions:
327-
args.append('-W' + opt)
328-
return args

Lib/subprocess.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,37 @@ def _eintr_retry_call(func, *args):
475475
continue
476476

477477

478+
# XXX This function is only used by multiprocessing and the test suite,
479+
# but it's here so that it can be imported when Python is compiled without
480+
# threads.
481+
482+
def _args_from_interpreter_flags():
483+
"""Return a list of command-line arguments reproducing the current
484+
settings in sys.flags and sys.warnoptions."""
485+
flag_opt_map = {
486+
'debug': 'd',
487+
# 'inspect': 'i',
488+
# 'interactive': 'i',
489+
'optimize': 'O',
490+
'dont_write_bytecode': 'B',
491+
'no_user_site': 's',
492+
'no_site': 'S',
493+
'ignore_environment': 'E',
494+
'verbose': 'v',
495+
'bytes_warning': 'b',
496+
'quiet': 'q',
497+
'hash_randomization': 'R',
498+
}
499+
args = []
500+
for flag, opt in flag_opt_map.items():
501+
v = getattr(sys.flags, flag)
502+
if v > 0:
503+
args.append('-' + opt * v)
504+
for opt in sys.warnoptions:
505+
args.append('-W' + opt)
506+
return args
507+
508+
478509
def call(*popenargs, timeout=None, **kwargs):
479510
"""Run command with arguments. Wait for command to complete or
480511
timeout, then return the returncode attribute.

Lib/test/support.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,8 +1596,7 @@ def strip_python_stderr(stderr):
15961596
def args_from_interpreter_flags():
15971597
"""Return a list of command-line arguments reproducing the current
15981598
settings in sys.flags and sys.warnoptions."""
1599-
from multiprocessing.util import _args_from_interpreter_flags
1600-
return _args_from_interpreter_flags()
1599+
return subprocess._args_from_interpreter_flags()
16011600

16021601
#============================================================
16031602
# Support for assertions about logging.

Tools/scripts/run_tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import os
1111
import sys
1212
import test.support
13+
try:
14+
import threading
15+
except ImportError:
16+
threading = None
1317

1418

1519
def is_multiprocess_flag(arg):
@@ -34,7 +38,7 @@ def main(regrtest_args):
3438
])
3539
if sys.platform == 'win32':
3640
args.append('-n') # Silence alerts under Windows
37-
if not any(is_multiprocess_flag(arg) for arg in regrtest_args):
41+
if threading and not any(is_multiprocess_flag(arg) for arg in regrtest_args):
3842
args.extend(['-j', '0']) # Use all CPU cores
3943
if not any(is_resource_use_flag(arg) for arg in regrtest_args):
4044
args.extend(['-u', 'all,-largefile,-audio,-gui'])

0 commit comments

Comments
 (0)