我有一个线程,constanlty等待通过套接字输入。它接收的东西很好,但如果我尝试pickle.loads
字符串,那么我收到一个错误。这很容易捕获,但这是它返回的错误:
Exception in thread Listening to <socket._socketobject object at 0x232cd00> at ('127.0.0.1', 48774):
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 505, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/[redacted]/Server.py", line 46, in Listen
pickled = pickle.loads(data)
File "/usr/lib/python2.7/pickle.py", line 1382, in loads
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 858, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 958, in load_binfloat
self.append(unpack('>d', self.read(8))[0])
error: unpack requires a string argument of length 8
我尝试并通过一个简单的try...except
检查成功地抓住了这个,没有规格,但我不知道如何捕捉这个'错误',因为pickle.struct.error
仅适用于少数情况
答案 0 :(得分:0)
是的,结果struct.error
是没有被捕获的错误......