[issue20854] multiprocessing.managers.Server: problem with returning proxy of registered object
Richard Oudkerk
report at bugs.python.org
Sat Mar 8 17:10:32 CET 2014
Richard Oudkerk added the comment:
I am not sure method_to_typeid and create_method were really intended to be public -- they are only used by Pool proxies.
You can maybe work around the problem by registering a second typeid without specifying callable. That can be used in method_to_typeid:
import multiprocessing.managers
class MyClass(object):
def __init__(self):
self._children = {}
def get_child(self, i):
return self._children.setdefault(i, type(self)())
def __repr__(self):
return '<MyClass %r>' % self._children
class MyManager(multiprocessing.managers.BaseManager):
pass
MyManager.register('MyClass', MyClass,
method_to_typeid = {'get_child': '_MyClass'})
MyManager.register('_MyClass',
method_to_typeid = {'get_child': '_MyClass'},
create_method=False)
if __name__ == '__main__':
m = MyManager()
m.start()
try:
a = m.MyClass()
b = a.get_child(1)
c = b.get_child(2)
d = c.get_child(3)
print a # <MyClass {1: <MyClass {2: <MyClass {3: <MyClass {}>}>}>}>
finally:
m.shutdown()
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20854>
_______________________________________
More information about the Python-bugs-list
mailing list