multiprocessing: How do I share a dict among multiple processes?

后端 未结 5 574
执念已碎
执念已碎 2020-11-22 11:49

A program that creates several processes that work on a join-able queue, Q, and may eventually manipulate a global dictionary D to store results. (

5条回答
  •  佛祖请我去吃肉
    2020-11-22 12:37

    multiprocessing is not like threading. Each child process will get a copy of the main process's memory. Generally state is shared via communication (pipes/sockets), signals, or shared memory.

    Multiprocessing makes some abstractions available for your use case - shared state that's treated as local by use of proxies or shared memory: http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes

    Relevant sections:

    • http://docs.python.org/library/multiprocessing.html#shared-ctypes-objects
    • http://docs.python.org/library/multiprocessing.html#module-multiprocessing.managers

提交回复
热议问题