Shared state in multiprocessing Processes

前端 未结 1 1990
遇见更好的自我
遇见更好的自我 2020-12-07 04:36

Please consider this code:

import time
from multiprocessing import Process

class Host(object):
    def __init__(self):
        self.id = None
    def callba         


        
相关标签:
1条回答
  • 2020-12-07 05:24

    multiprocessing runs stuff in separate processes. It is almost inconceivable that things are not copied as they're sent, as sharing stuff between processes requires shared memory or communication.

    In fact, if you peruse the module, you can see the amount of effort it takes to actually share anything between the processes after the diverge, either through explicit communication, or through explicitly-shared objects (which are of a very limited subset of the language, and have to be managed by a Manager).

    0 讨论(0)
提交回复
热议问题