我想从https://docs.python.org/3/library/multiprocessing.html#customized-managers运行示例代码(未修改):
from multiprocessing.managers import BaseManager
class MathsClass:
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__':
with MyManager() as manager:
maths = manager.Maths()
print(maths.add(4, 3)) # prints 7
print(maths.mul(7, 8)) # prints 56
但是,它会回复错误:
Traceback (most recent call last):
File "multithreadingbasexample.py", line 25, in <module>
print(maths.mul(7, 8)) # prints 56
File "c:\Anaconda2\lib\multiprocessing\managers.py
", line 602, in __exit__
self.shutdown()
AttributeError: 'MyManager' object has no attribute 'shutdown'
怎么了?
系统: Windows 7 64位, Python 2.7.13 | Anaconda自定义(64位)| (默认,2016年12月19日,13:29:36)[MSC v.1500 64 bit(AMD64)], 多处理0.70a1