Python管理器通过注册表访问dict

时间:2017-11-05 02:25:09

标签: python dictionary proxy multiprocessing

我有一个带有一个dict代理的经理。我想从不同的进程访问它。为简洁起见,示例代码仅使用一个进程,但假设我们没有直接引用它(就好像其他进程是从第一个进程创建的)。 我在typeName' d1'下注册了dict proxy dict1。所以我可以远程访问它。我检查了经理的注册表,并在那里看到了dict代理。 但是当我尝试通过调用d1来访问它时,我从远程获取了一个KeyError。我知道我可以创建一个方法来访问我的dict,但必须有一个直接的方法来访问dict代理根据文档(python 2,第16.6章)。

module.exports.Client1 = 'hello1'
module.exports.Client2 = 'hello2'

运行输出

from multiprocessing.managers import SyncManager
from sys import stderr

proxy = SyncManager()
proxy.start()

dict1 = proxy.dict({'k1': 'blah'})
proxy.register('d1', dict1)

# next line shows that d1 is bound method of manager
print >>stderr, 'd1 is', proxy.d1

# next line produces a KeyError
print 'The value of d1 is', proxy.d1()

1 个答案:

答案 0 :(得分:1)

发现调用注册新类型后必须启动代理服务器;似乎在代理启动后进行的注册将无法正常运行。

相关问题