[issue29795] Clarify how to share multiprocessing primitives

Max report at bugs.python.org
Sat Mar 11 14:25:49 EST 2017


New submission from Max:

It seems both me and many other people (judging from SO questions) are confused about whether it's ok to write this:

from multiprocessing import Process, Queue
q = Queue()

def f():
    q.put([42, None, 'hello'])

def main():
    p = Process(target=f)
    p.start()
    print(q.get())    # prints "[42, None, 'hello']"
    p.join()

if __name__ == '__main__':
    main()

It's not ok (doesn't work on Windows presumably because somehow when it's pickled, the connection between global queues in the two processes is lost; works on Linux, because I guess fork keeps more information than pickle, so the connection is maintained).

I thought it would be good to clarify in the docs that all the Queue() and Manager().* and other similar objects should be passed as parameters not just defined as globals.

----------
assignee: docs at python
components: Documentation
messages: 289454
nosy: docs at python, max
priority: normal
severity: normal
status: open
title: Clarify how to share multiprocessing primitives
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29795>
_______________________________________


More information about the Python-bugs-list mailing list