mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #12098: multiprocessing on Windows now starts child processes
using the same sys.flags as the current process. Backport from default branch.
This commit is contained in:
parent
ac0866f2ab
commit
8927e8f421
6 changed files with 72 additions and 18 deletions
|
@ -361,7 +361,8 @@ else:
|
||||||
return [sys.executable, '--multiprocessing-fork']
|
return [sys.executable, '--multiprocessing-fork']
|
||||||
else:
|
else:
|
||||||
prog = 'from multiprocessing.forking import main; main()'
|
prog = 'from multiprocessing.forking import main; main()'
|
||||||
return [_python_exe, '-c', prog, '--multiprocessing-fork']
|
opts = util._args_from_interpreter_flags()
|
||||||
|
return [_python_exe] + opts + ['-c', prog, '--multiprocessing-fork']
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -37,6 +37,7 @@ import weakref
|
||||||
import atexit
|
import atexit
|
||||||
import threading # we want threading to install it's
|
import threading # we want threading to install it's
|
||||||
# cleanup function before multiprocessing does
|
# cleanup function before multiprocessing does
|
||||||
|
from subprocess import _args_from_interpreter_flags
|
||||||
|
|
||||||
from multiprocessing.process import current_process, active_children
|
from multiprocessing.process import current_process, active_children
|
||||||
|
|
||||||
|
|
|
@ -482,6 +482,37 @@ def _eintr_retry_call(func, *args):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
# 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',
|
||||||
|
'hash_randomization': 'R',
|
||||||
|
'py3k_warning': '3',
|
||||||
|
}
|
||||||
|
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, **kwargs):
|
def call(*popenargs, **kwargs):
|
||||||
"""Run command with arguments. Wait for command to complete, then
|
"""Run command with arguments. Wait for command to complete, then
|
||||||
return the returncode attribute.
|
return the returncode attribute.
|
||||||
|
|
|
@ -2400,11 +2400,43 @@ class TestNoForkBomb(unittest.TestCase):
|
||||||
self.assertEqual('', err.decode('ascii'))
|
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,
|
testcases_other = [OtherTest, TestInvalidHandle, TestInitializers,
|
||||||
TestStdinBadfiledescriptor, TestTimeouts, TestNoForkBomb]
|
TestStdinBadfiledescriptor, TestTimeouts, TestNoForkBomb,
|
||||||
|
TestFlags]
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
|
@ -1344,22 +1344,7 @@ def py3k_bytes(b):
|
||||||
def args_from_interpreter_flags():
|
def args_from_interpreter_flags():
|
||||||
"""Return a list of command-line arguments reproducing the current
|
"""Return a list of command-line arguments reproducing the current
|
||||||
settings in sys.flags."""
|
settings in sys.flags."""
|
||||||
flag_opt_map = {
|
return subprocess._args_from_interpreter_flags()
|
||||||
'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
|
|
||||||
|
|
||||||
def strip_python_stderr(stderr):
|
def strip_python_stderr(stderr):
|
||||||
"""Strip the stderr of a Python process from potential debug output
|
"""Strip the stderr of a Python process from potential debug output
|
||||||
|
|
|
@ -214,6 +214,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #12098: multiprocessing on Windows now starts child processes
|
||||||
|
using the same sys.flags as the current process. Initial patch by
|
||||||
|
Sergey Mezentsev.
|
||||||
|
|
||||||
- Issue #8862: Fixed curses cleanup when getkey is interrputed by a signal.
|
- Issue #8862: Fixed curses cleanup when getkey is interrputed by a signal.
|
||||||
|
|
||||||
- Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
|
- Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue