Need help with multiprocessing.manager and passing the manager a multiprocessing.Connection

Metalone jcb at iteris.com
Wed Jan 6 14:26:41 EST 2010


The following code snippet is taken from the Python 2.6
multiprocessing documentation with a simple change and this change
does not work.  I would like to know how to make it work or something
similar.
I want to pass a Connection object to the MathsClass.
I get the following error on Windows:

Traceback (most recent call last):
  File "c:\apps\python26\lib\multiprocessing\managers.py", line 214,
in serve_cl
ient
    request = recv()
TypeError: Required argument 'handle' (pos 1) not found


from multiprocessing.managers import BaseManager
from multiprocessing import Pipe        # I added this

class MathsClass(object):
    def set(self, conn):          # I added the set() function
        self.conn = conn
    def add(self, x, y):
        return x + y
    def mul(self, x, y):
        return x * y

class MyManager(BaseManager):
    pass

MyManager.register('Maths', MathsClass)

if __name__ == '__main__':
    parent_conn, child_conn = Pipe()    # I added this
    manager = MyManager()
    manager.start()
    maths = manager.Maths()
    print maths.add(4, 3)         # prints 7
    print maths.mul(7, 8)         # prints 56
    maths.set(child_conn)       # I added this, error is thrown here



More information about the Python-list mailing list