Message212221
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 |
|
Date |
User |
Action |
Args |
2014-02-25 22:00:00 | Naftali.Harris | set | recipients:
+ Naftali.Harris |
2014-02-25 22:00:00 | Naftali.Harris | set | messageid: <1393365600.9.0.351514373601.issue20775@psf.upfronthosting.co.za> |
2014-02-25 22:00:00 | Naftali.Harris | link | issue20775 messages |
2014-02-25 22:00:00 | Naftali.Harris | create | |
|