Eryk Sun <eryk...@gmail.com> added the comment:

> I am not going to close it as I am unsure if it is by design that 
> Windows and Unix python acts differently.

For compatibility, a script should support the spawn start method. Spawning 
child processes is the only available start method in Windows, and, as of 
Python 3.8 (see issue 33725), it's the default start method in macOS. This 
entails passing picklable objects as arguments or with a multiprocessing.Queue 
or multiprocessing.Pipe -- instead of relying on global values that get 
inherited via fork. 

With a pool you can set up globals with an initializer function. Here's an 
example of the latter that manually selects the spawn start method:

    import multiprocessing as mp

    def pool_init(x_value, y_value):
        global x, y
        x = x_value
        y = y_value

    if __name__ == '__main__':
        mp.set_start_method('spawn')
        pool = mp.Pool(processes=2, initializer=pool_init,
                        initargs=(mp.Value('i', 0), mp.Value('i', 0)))

----------
nosy: +eryksun
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39255>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to