我将有一个子流程来发送 LDAP 查询和其他子流程来检索响应。在两个进程之间共享 LDAP 对象存在问题。有人可以指出我的解决方案吗?
import ldap
from multiprocessing import Process
def send_ldap(ldap_conn):
print ldap_conn
def receive_ldap(ldap_conn):
print ldap_conn
def main():
ldap_conn = ldap.initialize('ldap://abc:12345')
ldap_sender = Process(target=send_ldap, args=(ldap_conn,))
ldap_receiver = Process(target=receive_ldap, args=(ldap_conn,))
ldap_sender.start()
if __name__ == '__main__':
main()
错误与泡菜模块有关:
Traceback (most recent call last):
File "t.py", line 22, in <module>
main()
File "t.py", line 16, in main
ldap_sender.start()
File "c:\python27\lib\multiprocessing\process.py", line 130, in start
self._popen = Popen(self)
File "c:\python27\lib\multiprocessing\forking.py", line 277, in __init__
dump(process_obj, to_child, HIGHEST_PROTOCOL)
File "c:\python27\lib\multiprocessing\forking.py", line 199, in dump
ForkingPickler(file, protocol).dump(obj)
File "c:\python27\lib\pickle.py", line 224, in dump
self.save(obj)
File "c:\python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "c:\python27\lib\pickle.py", line 419, in save_reduce
save(state)
File "c:\python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "c:\python27\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "c:\python27\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "c:\python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "c:\python27\lib\pickle.py", line 548, in save_tuple
save(element)
File "c:\python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "c:\python27\lib\pickle.py", line 725, in save_inst
save(stuff)
File "c:\python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "c:\python27\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "c:\python27\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "c:\python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "c:\python27\lib\pickle.py", line 725, in save_inst
save(stuff)
File "c:\python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "c:\python27\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "c:\python27\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "c:\python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
Traceback (most recent call last):
File "c:\python27\lib\pickle.py", line 396, in save_reduce
File "<string>", line 1, in <module>
File "c:\python27\lib\multiprocessing\forking.py", line 381, in main
save(cls)
File "c:\python27\lib\pickle.py", line 286, in save
self = load(from_parent)
File "c:\python27\lib\pickle.py", line 1378, in load
f(self, obj) # Call unbound method with explicit self
File "c:\python27\lib\pickle.py", line 748, in save_global
return Unpickler(file).load()
File "c:\python27\lib\pickle.py", line 858, in load
(obj, module, name))
pickle.PicklingError: Can't pickle <type 'thread.lock'>: it's not found as thread.lock
dispatch[key](self)
File "c:\python27\lib\pickle.py", line 880, in load_eof
raise EOFError
EOFError