New submission from Antoine Pitrou:

The following script:


import multiprocessing
import os

def f():
    pass

multiprocessing.Lock()

if __name__ == "__main__":
    ctx = multiprocessing.get_context('forkserver')
    # modname is the script's importable name (not "__main__")
    modname = os.path.basename(__file__).split(".")[0]
    ctx.set_forkserver_preload([modname])
    proc = ctx.Process(target=f)
    proc.start()
    proc.join()


Fails with the following error:

Traceback (most recent call last):
  File 
"/home/antoine/miniconda3/envs/dask35/lib/python3.5/multiprocessing/forkserver.py",
 line 178, in main
    _serve_one(s, listener, alive_r, handler)
  File 
"/home/antoine/miniconda3/envs/dask35/lib/python3.5/multiprocessing/forkserver.py",
 line 212, in _serve_one
    code = spawn._main(child_r)
  File 
"/home/antoine/miniconda3/envs/dask35/lib/python3.5/multiprocessing/spawn.py", 
line 115, in _main
    prepare(preparation_data)
  File 
"/home/antoine/miniconda3/envs/dask35/lib/python3.5/multiprocessing/spawn.py", 
line 221, in prepare
    set_start_method(data['start_method'])
  File 
"/home/antoine/miniconda3/envs/dask35/lib/python3.5/multiprocessing/context.py",
 line 231, in set_start_method
    raise RuntimeError('context has already been set')
RuntimeError: context has already been set


This makes set_forkserver_preload() quite fragile if you preload any library 
that may create multiprocessing resources (such as locks) at the top level.

----------
components: Library (Lib)
messages: 281565
nosy: davin, pitrou, sbt
priority: normal
severity: normal
stage: needs patch
status: open
title: set_forkserver_preload() can crash the forkserver if preloaded module 
instantiate multiprocessing classes
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28779>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to