I am trying to pass a custom Queue between processes using the multiprocessing module. The problem is that I do not get all the methods going through the other side. According to the docs.
A proxy object has methods that call the corresponding methods of its referent (although not every referent method will necessarily be available through a proxy server). Proxies can usually be used in most ways that a referent can
But he does not say why or around. I am wondering if anyone knows about this.
Here is a small example of what I'm trying to do.
Server:
from multiprocessing.managers import BaseManager from Queue import Queue class KeyHandler(Queue): def __init__(self, elements=[]): Queue.__init__(self) for element in elements: self.put(element) def __iter__(self): return iter(self.get, object()) def __call__(self): return self class QueueManager(BaseManager): pass keyhandler = KeyHandler(range(10)) QueueManager.register('keyhandler', callable=keyhandler) manager = QueueManager(address=('', 50000), authkey='foobar') server = manager.get_server() server.serve_forever()
Customer:
from multiprocessing.managers import BaseManager class QueueManager(BaseManager): pass QueueManager.register('keyhandler') manager = QueueManager(address=('', 50000), authkey='foobar') manager.connect() keyhandler = manager.keyhandler() for elem in keyhandler: print elem
Traceback:
Traceback (most recent call last): File "client2.py", line 14, in <module> for elem in keyhandler: TypeError: 'AutoProxy[keyhandler]' object is not iterable
The __call__ method works, but the __iter__ method __iter__ not work. Can I make / get around this somehow?
source share