python - Putting a multiprocessing.Queue in a multiprocessing.Queue explodes -
the following code throws exception , prints 123 in both python 2.7 , 3.3.
from multiprocessing import queue class pool(object): def __init__(self): self.q = queue() p = pool() p.q.put(p) print(123)
it's sort of race condition can seen here:
yuv@yuvpad2:~/$ python3.3 t.py 123 traceback (most recent call last): file "/home/yuv/downloads/python-3.3.0/lib/multiprocessing/queues.py", line 249, in _feed yuv@yuvpad2:~/$
the full error runtimeerror: queue objects should shared between processes through inheritance
, traceback doesn't @ explain how/where happens. source of problem object in queue can't reference queue. real use case worker object , pool object, worker reports finished working pool's queue
. wanted worker send worker queue
.
the reason i'm not using queue.queue
,although multithreading work case, because in python 2.7 there's bug makes queue.get() ignore ctrl-c annoying.
is there way pattern cleanly?
i guess there couple of ways this, without knowing wan't it's hard recommend one.
i guess easiest 1 using 2 different queues purpose. 1 incoming workers , 1 fore finished workers.