multiprocessing: child process share changes to global variable
Jason Friedman
jsf80238 at gmail.com
Tue Dec 3 22:14:40 EST 2013
> #--------------- temp.py -------------------------
> #run at Python 2.7 command prompt
> import time
> import multiprocessing as mp
> lst = []
> lstlst = []
>
> def alist(x):
> lst.append(x)
> lstlst.append(lst)
> print "a"
> return lst
>
> if __name__=='__main__':
> pool = mp.Pool(3)
> print pool.map(alist,range(3)) #UNEXPECTED RESULTS
> print "b"
> time.sleep(0.1)
>
> print "c"
> print lst
> print lstlst
> --
I get several different results:
$ for i in {1..1000}; do
> python2.7 temp.py | md5sum >> result
> done
$ wc -l result
1000 result
$ sort result | uniq | wc -l
9
More information about the Python-list
mailing list