[Python-checkins] cpython: Move private function _args_from_interpreter_flags() to subprocess.py, so
antoine.pitrou
python-checkins at python.org
Fri May 18 18:36:02 CEST 2012
http://hg.python.org/cpython/rev/2034b3de1144
changeset: 77036:2034b3de1144
user: Antoine Pitrou <solipsis at pitrou.net>
date: Fri May 18 18:33:07 2012 +0200
summary:
Move private function _args_from_interpreter_flags() to subprocess.py, so
that it can be imported when threads are disabled.
(followup to issue #12098)
files:
Lib/multiprocessing/util.py | 30 +-----------------------
Lib/subprocess.py | 31 +++++++++++++++++++++++++
Lib/test/support.py | 3 +-
Tools/scripts/run_tests.py | 6 ++++-
4 files changed, 38 insertions(+), 32 deletions(-)
diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py
--- a/Lib/multiprocessing/util.py
+++ b/Lib/multiprocessing/util.py
@@ -14,6 +14,7 @@
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 @@
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
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -475,6 +475,37 @@
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.
diff --git a/Lib/test/support.py b/Lib/test/support.py
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -1596,8 +1596,7 @@
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.
diff --git a/Tools/scripts/run_tests.py b/Tools/scripts/run_tests.py
--- a/Tools/scripts/run_tests.py
+++ b/Tools/scripts/run_tests.py
@@ -10,6 +10,10 @@
import os
import sys
import test.support
+try:
+ import threading
+except ImportError:
+ threading = None
def is_multiprocess_flag(arg):
@@ -34,7 +38,7 @@
])
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'])
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list