Alex Rivera | Logout

TypeError: AutoProxy object is not iterable - multiprocessing

Asked 2011-05-17T10:30:56.307
10

consider the following server code :

from multiprocessing.managers import BaseManager, BaseProxy

def baz(aa) :
    print "aaa"
    l = []
    for i in range(3) :
      l.append(aa)
    return l

class SolverManager(BaseManager): pass

manager = SolverManager(address=('127.0.0.1', 50000), authkey='mpm')
manager.register('solver', baz)

server = manager.get_server()
server.serve_forever()

and the associated client :

import sys
from multiprocessing.managers import BaseManager, BaseProxy

class SolverManager(BaseManager): pass

def main(args) :
    SolverManager.register('solver')
    m = SolverManager(address=('127.0.0.1', 50000), authkey='mpm')
    m.connect()

    for i in m.solver(args[1]):
        print i

if __name__ == '__main__':
    sys.exit(main(sys.argv))

I think I'm missing something important here. My guess is that I have to subclass the BaseProxy class to provide an iterable object, but so far I haven't managed to get it right.

when I run the client I get this error :

Traceback (most recent call last):
  File "mpmproxy.py", line 17, in <module>
    sys.exit(main(sys.argv))
  File "mpmproxy.py", line 13, in main
    for i in m.solver(args[1]):
TypeError: 'AutoProxy[solver]' object is not iterable

however if I try to print it, the list is there ... Maybe it has also something to do with the way data is serialized between client and server ...

in the documentation there is a similar case (with a generator) and they use the following class to access the data :

class GeneratorProxy(BaseProxy):
    _exposed_ = ('next', '__next__')
    def __iter__(self):
        return self
    def next(self):
        return self._callmethod('next')
    def __next__(self):
        return self._callmethod('__next__')

shall I do something similar ? Can anybody give me an example and explain to me how this works ?

Edit
Report

1 Answer

0

Indeed, to be iterable your class needs to define the __iter__ method that BaseProxy defines, so I guess inheritance is the right way to go !

answered 2011-05-17T10:50:01.280

Your Answer