我做了 2 个应用程序:客户端从 sql 服务器(10k 行)中提取数据,并通过套接字将腌制的每一行发送到“收集器”服务器。服务器使用twisted(这是强制性的)并接收每一行,将其解压并将数据存储在另一个sql服务器中。
每次我开始从客户端向服务器发送数据时,在前 200 行(每次不同的行)中,服务器都会抛出异常:有时它类似于:
Traceback (most recent call last):
File "collector2.py", line 81, in dataReceived
self.count,account = pickle.loads(data)
File "/usr/lib/python2.6/pickle.py", line 1374, in loads
return Unpickler(file).load()
File "/usr/lib/python2.6/pickle.py", line 858, in load
dispatch[key](self)
File "/usr/lib/python2.6/pickle.py", line 1138, in load_pop
del self.stack[-1]
IndexError: list assignment index out of range
但并非每次都一样。打印我的异常我红色:异常:从空列表中弹出异常:列表索引超出范围异常:“'”异常:列表分配索引超出范围
另一个奇怪的错误是:文件“/usr/lib/python2.6/pickle.py”,第 1124 行,在 find_class 导入(模块)异常中。ImportError: No module named ond'
for i in listaSAI:
crm={}
try:
crm['uid']=i[0]
except:
crm['uid']=None
try:
crm['type_cond']=i[01]
except:
crm['type_cond']=None
try:
crm['population_id']=i[2]
except:
crm['population_id']=None
try:
crm['product_id']=i[3]
except:
crm['product_id']=None
try:
crm['a_id']=i[4]
except:
crm['a_id']=None
try:
crm['status']=i[5]
except:
crm['status']=None
#time.sleep(0.001)
serialized = pickle.dumps((count,crm))
#print "sent num", count, crm
s.sendall(serialized)
count += 1
还有我的服务器:
def dataReceived(self, data):
try:
self.count,account = pickle.loads(data)
except Exception as e:
print "Eccezione:", e
print self.count+1
print "DISAGIO", data
print traceback.print_exc()
在我的客户端打印数据告诉我一切正常。 如果我尝试在客户端使用 time.sleep(0.01) 减慢发送过程,一切都很好,并且不会引发异常。
我可以做些什么来调试我的代码?
ps 我怀疑 exceptions.ImportError: No module named ond' 指的是 crm 中的“type_cond”键。