cpython: 1a955981b263 (original) (raw)
Mercurial > cpython
changeset 105574:1a955981b263 3.5
Issue #28779: multiprocessing.set_forkserver_preload() would crash the forkserver process if a preloaded module instantiated some multiprocessing objects such as locks. [#28779]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Sat, 10 Dec 2016 17:13:16 +0100 |
parents | 5d51ac0be72a |
children | f3b9fd41b5cb 3484933ba904 |
files | Lib/multiprocessing/context.py Lib/multiprocessing/spawn.py Lib/test/_test_multiprocessing.py Lib/test/mp_preload.py Misc/NEWS |
diffstat | 5 files changed, 37 insertions(+), 2 deletions(-)[+] [-] Lib/multiprocessing/context.py 2 Lib/multiprocessing/spawn.py 2 Lib/test/_test_multiprocessing.py 13 Lib/test/mp_preload.py 18 Misc/NEWS 4 |
line wrap: on
line diff
--- a/Lib/multiprocessing/context.py +++ b/Lib/multiprocessing/context.py @@ -195,7 +195,7 @@ class BaseContext(object): def get_start_method(self, allow_none=False): return self._name
- def set_start_method(self, method, force=False): raise ValueError('cannot set start method of concrete context')
--- a/Lib/multiprocessing/spawn.py +++ b/Lib/multiprocessing/spawn.py @@ -218,7 +218,7 @@ def prepare(data): process.ORIGINAL_DIR = data['orig_dir'] if 'start_method' in data:
set_start_method(data['start_method'])[](#l2.7)
set_start_method(data['start_method'], force=True)[](#l2.8)
if 'init_main_from_name' in data: _fixup_main_from_name(data['init_main_from_name'])
--- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -3728,6 +3728,19 @@ class TestStartMethod(unittest.TestCase) self.assertTrue(methods == ['fork', 'spawn'] or methods == ['fork', 'spawn', 'forkserver'])
- def test_preload_resources(self):
if multiprocessing.get_start_method() != 'forkserver':[](#l3.8)
self.skipTest("test only relevant for 'forkserver' method")[](#l3.9)
name = os.path.join(os.path.dirname(__file__), 'mp_preload.py')[](#l3.10)
rc, out, err = test.support.script_helper.assert_python_ok(name)[](#l3.11)
out = out.decode()[](#l3.12)
err = err.decode()[](#l3.13)
if out.rstrip() != 'ok' or err != '':[](#l3.14)
print(out)[](#l3.15)
print(err)[](#l3.16)
self.fail("failed spawning forkserver or grandchild")[](#l3.17)
Check that killing process does not leak named semaphores
new file mode 100644 --- /dev/null +++ b/Lib/test/mp_preload.py @@ -0,0 +1,18 @@ +import multiprocessing + +multiprocessing.Lock() + + +def f():
- ctx = multiprocessing.get_context("forkserver")
- modname = "test.mp_preload"
Make sure it's importable
- import(modname)
- ctx.set_forkserver_preload([modname])
- proc = ctx.Process(target=f)
- proc.start()
- proc.join()
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -124,6 +124,10 @@ Core and Builtins Library ------- +- Issue #28779: multiprocessing.set_forkserver_preload() would crash the