LDAP クエリを送信する 1 つのサブプロセスと、応答を取得する別のサブプロセスを作成します。両方のプロセス間で 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()
エラーは pickle モジュールにあります:
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