mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
#12098: Make multiprocessing's child processes inherit sys.flags on Windows
Initial patch by Sergey Mezentsev.
This commit is contained in:
parent
cca802e354
commit
77c84f2def
5 changed files with 73 additions and 20 deletions
|
@ -324,7 +324,8 @@ else:
|
|||
return [sys.executable, '--multiprocessing-fork']
|
||||
else:
|
||||
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():
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
# Licensed to PSF under a Contributor Agreement.
|
||||
#
|
||||
|
||||
import sys
|
||||
import functools
|
||||
import itertools
|
||||
import weakref
|
||||
|
@ -295,3 +296,33 @@ class ForkAwareLocal(threading.local):
|
|||
register_after_fork(self, lambda obj : obj.__dict__.clear())
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue