]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Move private function _args_from_interpreter_flags() to subprocess.py, so
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 18 May 2012 16:33:07 +0000 (18:33 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 18 May 2012 16:33:07 +0000 (18:33 +0200)
that it can be imported when threads are disabled.
(followup to issue #12098)

Lib/multiprocessing/util.py
Lib/subprocess.py
Lib/test/support.py
Tools/scripts/run_tests.py

index 7c710810568e599f332fe4eccc96841ea806af56..cbb01c925b6b075ea489b8bdfac1452a24ebb20c 100644 (file)
@@ -14,6 +14,7 @@ import weakref
 import atexit
 import threading        # we want threading to install it's
                         # cleanup function before multiprocessing does
+from subprocess import _args_from_interpreter_flags
 
 from multiprocessing.process import current_process, active_children
 
@@ -297,32 +298,3 @@ class ForkAwareLocal(threading.local):
     def __reduce__(self):
         return type(self), ()
 
-#
-# Get options for python to produce the same sys.flags
-#
-
-def _args_from_interpreter_flags():
-    """Return a list of command-line arguments reproducing the current
-    settings in sys.flags and sys.warnoptions."""
-    flag_opt_map = {
-        'debug': 'd',
-        # 'inspect': 'i',
-        # 'interactive': 'i',
-        'optimize': 'O',
-        'dont_write_bytecode': 'B',
-        'no_user_site': 's',
-        'no_site': 'S',
-        'ignore_environment': 'E',
-        'verbose': 'v',
-        'bytes_warning': 'b',
-        'quiet': 'q',
-        'hash_randomization': 'R',
-    }
-    args = []
-    for flag, opt in flag_opt_map.items():
-        v = getattr(sys.flags, flag)
-        if v > 0:
-            args.append('-' + opt * v)
-    for opt in sys.warnoptions:
-        args.append('-W' + opt)
-    return args
index 410ae2918b8d4e6a2ccaf4f68e6f636e6b989504..15398914041fbc3fd8dd298749a4fd4f8cb68303 100644 (file)
@@ -475,6 +475,37 @@ def _eintr_retry_call(func, *args):
             continue
 
 
+# XXX This function is only used by multiprocessing and the test suite,
+# but it's here so that it can be imported when Python is compiled without
+# threads.
+
+def _args_from_interpreter_flags():
+    """Return a list of command-line arguments reproducing the current
+    settings in sys.flags and sys.warnoptions."""
+    flag_opt_map = {
+        'debug': 'd',
+        # 'inspect': 'i',
+        # 'interactive': 'i',
+        'optimize': 'O',
+        'dont_write_bytecode': 'B',
+        'no_user_site': 's',
+        'no_site': 'S',
+        'ignore_environment': 'E',
+        'verbose': 'v',
+        'bytes_warning': 'b',
+        'quiet': 'q',
+        'hash_randomization': 'R',
+    }
+    args = []
+    for flag, opt in flag_opt_map.items():
+        v = getattr(sys.flags, flag)
+        if v > 0:
+            args.append('-' + opt * v)
+    for opt in sys.warnoptions:
+        args.append('-W' + opt)
+    return args
+
+
 def call(*popenargs, timeout=None, **kwargs):
     """Run command with arguments.  Wait for command to complete or
     timeout, then return the returncode attribute.
index 5259e2705c2320f555a59921812d41b8e420c421..e43dbad34de8621233a9763f861320f4fa216d68 100644 (file)
@@ -1596,8 +1596,7 @@ def strip_python_stderr(stderr):
 def args_from_interpreter_flags():
     """Return a list of command-line arguments reproducing the current
     settings in sys.flags and sys.warnoptions."""
-    from multiprocessing.util import _args_from_interpreter_flags
-    return _args_from_interpreter_flags()
+    return subprocess._args_from_interpreter_flags()
 
 #============================================================
 # Support for assertions about logging.
index f750e192a0ead1d4ce25b8391987b31b0c5877cc..e2a205097812e628e9518cda63570fb3e84a7d7f 100755 (executable)
@@ -10,6 +10,10 @@ simply passing a -u option to this script.
 import os
 import sys
 import test.support
+try:
+    import threading
+except ImportError:
+    threading = None
 
 
 def is_multiprocess_flag(arg):
@@ -34,7 +38,7 @@ def main(regrtest_args):
                  ])
     if sys.platform == 'win32':
         args.append('-n')         # Silence alerts under Windows
-    if not any(is_multiprocess_flag(arg) for arg in regrtest_args):
+    if threading and not any(is_multiprocess_flag(arg) for arg in regrtest_args):
         args.extend(['-j', '0'])  # Use all CPU cores
     if not any(is_resource_use_flag(arg) for arg in regrtest_args):
         args.extend(['-u', 'all,-largefile,-audio,-gui'])