diff options
author | Kristján Valur Jónsson <sweskman@gmail.com> | 2013-03-19 22:07:35 (GMT) |
---|---|---|
committer | Kristján Valur Jónsson <sweskman@gmail.com> | 2013-03-19 22:07:35 (GMT) |
commit | 8927e8f4211dc50b87a6365ed7281452a1931ebf (patch) | |
tree | c519bb98128d6fa159ea2ea9b2e1a8c9f2b69067 /Lib/test | |
parent | ac0866f2ab9aa43c635618681682dd9f6da6219e (diff) | |
download | cpython-8927e8f4211dc50b87a6365ed7281452a1931ebf.zip cpython-8927e8f4211dc50b87a6365ed7281452a1931ebf.tar.gz cpython-8927e8f4211dc50b87a6365ed7281452a1931ebf.tar.bz2 |
Issue #12098: multiprocessing on Windows now starts child processes
using the same sys.flags as the current process.
Backport from default branch.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_multiprocessing.py | 34 | ||||
-rw-r--r-- | Lib/test/test_support.py | 17 |
2 files changed, 34 insertions, 17 deletions
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index 9b3f0a9..8091a9f 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -2400,11 +2400,43 @@ class TestNoForkBomb(unittest.TestCase): self.assertEqual('', err.decode('ascii')) # +# Issue 12098: check sys.flags of child matches that for parent +# + +class TestFlags(unittest.TestCase): + @classmethod + def run_in_grandchild(cls, conn): + conn.send(tuple(sys.flags)) + + @classmethod + def run_in_child(cls): + import json + r, w = multiprocessing.Pipe(duplex=False) + p = multiprocessing.Process(target=cls.run_in_grandchild, args=(w,)) + p.start() + grandchild_flags = r.recv() + p.join() + r.close() + w.close() + flags = (tuple(sys.flags), grandchild_flags) + print(json.dumps(flags)) + + def test_flags(self): + import json, subprocess + # start child process using unusual flags + prog = ('from test.test_multiprocessing import TestFlags; ' + + 'TestFlags.run_in_child()') + data = subprocess.check_output( + [sys.executable, '-E', '-S', '-O', '-c', prog]) + child_flags, grandchild_flags = json.loads(data.decode('ascii')) + self.assertEqual(child_flags, grandchild_flags) +# # # testcases_other = [OtherTest, TestInvalidHandle, TestInitializers, - TestStdinBadfiledescriptor, TestTimeouts, TestNoForkBomb] + TestStdinBadfiledescriptor, TestTimeouts, TestNoForkBomb, + TestFlags] # # diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 034a374..b3076c1 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -1344,22 +1344,7 @@ def py3k_bytes(b): def args_from_interpreter_flags(): """Return a list of command-line arguments reproducing the current settings in sys.flags.""" - flag_opt_map = { - 'bytes_warning': 'b', - 'dont_write_bytecode': 'B', - 'ignore_environment': 'E', - 'no_user_site': 's', - 'no_site': 'S', - 'optimize': 'O', - 'py3k_warning': '3', - 'verbose': 'v', - } - args = [] - for flag, opt in flag_opt_map.items(): - v = getattr(sys.flags, flag) - if v > 0: - args.append('-' + opt * v) - return args + return subprocess._args_from_interpreter_flags() def strip_python_stderr(stderr): """Strip the stderr of a Python process from potential debug output |