我想將超時應用於我通常工作正常的方法之一。我已經試過這個簡單的打印功能的代碼,一切正常,但現在我得到錯誤。你能告訴我問題在哪裏嗎?Python - 多線程pickle.PicklingError錯誤
方法self.check_flights
應運行最大__TIMEOUT__
秒。
下面的代碼是在這是在一個類中的方法some_class
try:
p = multiprocessing.Process(target=self.check_flights, args=(destination, start_date , end_date_2))
p.start()
p.join(__TIMEOUT__)
if p.is_alive():
print 'TIMEOUT'
p.terminate()
p.join()
except Exception as e:
raise e
>ERROR: pickle.PicklingError: Can't pickle <class __main__.some_class at 0x02DD10A0>: it's not the same object as __main__.some_class
編輯:該超時的解決方案是從THIS SO回答
編輯2:爲了更詳細說明它,我附加另一行的錯誤:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
self = load(from_parent)
File "C:\Python27\lib\pickle.py", line 1378, in load
return Unpickler(file).load()
File "C:\Python27\lib\pickle.py", line 858, in load
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 880, in load_eof
raise EOFError
EOFError
能否請您複製/粘貼或共享莫名其妙完整的類? – Geeocode
您是否使用過'if __name__ =='__main __':'? – Geeocode
@GyörgySolymosi是的,我用過它。這是整個代碼http://pastebin.com/uG0qSvhU –