Python Multiprocess diff between Windows and Linux

后端 未结 1 1048
感动是毒
感动是毒 2020-12-06 19:00

I have a script called jobrunner.py that calls class methods in main.py. See below...

# jobrunner.py
from multiprocessing import Process
import main
from mai         


        
相关标签:
1条回答
  • 2020-12-06 19:31

    You shouldn't expect the values of global variables that you set in the parent process to be automatically propagated to the child processes.

    Your code happens to work on Unix-like platforms because on those platforms multiprocessing uses fork(). This means that every child processes gets a copy of the parent process's address space, including all global variables.

    This isn't the case on Windows; every variable from the parent process that needs to be accessed by the child has to be explicitly passed down or placed in shared memory.

    Once you do this, your code will work on both Unix and Windows.

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