1
我試圖用泡菜來編碼一個類的實例和整個插座發送它,它在另一端進行解碼,但是在到達其他調用pickle.loads()時拋出結尾AttributeError: 'module' object has no attribute ''
。圍繞谷歌搜索後,我證實,鹹菜正確導入包含類definition.I想不通模塊爲什麼它尋找一個沒有名字AttributeError的:「模塊」對象有沒有屬性「」使用泡菜在套接字時
函數用來接收分組
def run(self):
while self.alive.isSet():
try:
cmd = self.cmd_q.get(True, 0.1)
self.log.debug('Q Returned')
self.handlers[cmd.type](cmd)
except Queue.Empty as e:
#self.log.debug('Q Returned Empty')
pass
if self.connected.isSet():
self.log.debug('checking packets')
if self.conn:
x = select.select((self.conn,),(),(), 0.1)
self.log.debug('SERVER returned')
else:
x = select.select((self.sock,),(),(), 0.1)
self.log.debug('CLIENT returned')
if len(x[0]) != 0:
self.log.debug('Got Packet')
packet = x[0][0].makefile('rwb').readline()
self.__reply_receive(packet)
一個屬性
用於發送
def __handle_send(self, cmd):
self.log.debug('Sending.....')
if self.connected.isSet():
packet = pickle.dumps(cmd.data,pickle.HIGHEST_PROTOCOL)
if self.conn:
self.conn.send(packet + '\n')
else:
self.sock.send(packet + '\n')
self.log.debug('Sent!')
的功能和類定義
class Packet(object):
"""
LINEUP (line)
UPDATE (dict)
INPUT (line)
DISCONN None
TEST (line)
"""
LINEUP, UPDATE, INPUT, DISCONN, TEST = range(5)
def __init__(self, type, data = 'blarg'):
self.type = type
self.data = data
你試過'print'ing傾銷的字符串,並手動在同一側再次加載呢?另一方面? – katrielalex 2012-03-25 21:58:26