python singleton into multiprocessing

前端 未结 5 743
时光取名叫无心
时光取名叫无心 2021-01-13 02:53

How can I code to share the same instance of a \"singletonic\" class among processes?

5条回答
  •  轮回少年
    2021-01-13 03:34

    I do not think you can share the instance between the processes, but you can have the instance access shared memory: http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes to control it's state if that is really what you want to do.

    However, as stated in other answers, it might be easier to achieve what you want with a Queue.

提交回复
热议问题