How to inherit from a multiprocessing queue?
With the following code, it seems that the queue instance passed to the
worker isn't initialized:
from multiprocessing import Process
from multiprocessing.queues import Queue
class MyQueue(Queue):
def __init__(self, name):
Queue.__init__(self)
self.name = name
def worker(queue):
print queue.name
if __name__ == "__main__":
queue = MyQueue("My Queue")
p = Process(target=worker, args=(queue,))
p.start()
p.join()
This throws:
... line 14, in worker
print queue.name
AttributeError: 'MyQueue' object has no attribute 'name'
I can't re-initialize the queue, because I'll loose the original value of
queue.name, even passing the queue's name as an argument to the worker
(this should work, but it's not a clean solution).
So, how can inherit from multiprocessing.queues.Queue without getting this
error?
No comments:
Post a Comment