This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Naftali.Harris
Recipients Naftali.Harris
Date 2014-02-25.22:00:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1393365600.9.0.351514373601.issue20775@psf.upfronthosting.co.za>
In-reply-to
Content
Hi everyone,

It appears that if you use a global variable in a function that you pass to Pool.map, but modify that global variable after instantiating the Pool, then the modification will not be reflected when Pool.map calls that function.

Here's a short script, (also attached), that demonstrates what I mean:

$ cat reproduces.py
from multiprocessing import Pool

name = "Not Updated"
def f(ignored):
    print(name)


def main():
    global name
    p = Pool(3)
    name = "Updated"
    p.map(f, range(3))

if __name__ == "__main__":
    main()
$ python reproduces.py 
Not Updated
Not Updated
Not Updated


If the `name = "Updated"' line is moved above the `p = Pool(3)' line, then the script will print "Updated" three times instead.

This behavior is present in versions 2.6, 2.7, 3.1, 3.2, 3.3, and 3.4. I run Linux Mint 14 (nadia), on an Intel i5-3210M processor (four cores).

Is this expected behavior?

Thanks very much,

Naftali
History
Date User Action Args
2014-02-25 22:00:00Naftali.Harrissetrecipients: + Naftali.Harris
2014-02-25 22:00:00Naftali.Harrissetmessageid: <1393365600.9.0.351514373601.issue20775@psf.upfronthosting.co.za>
2014-02-25 22:00:00Naftali.Harrislinkissue20775 messages
2014-02-25 22:00:00Naftali.Harriscreate