我正在使用Python多处理模块来处理来自websocket的响应。
if __name__ == '__main__':
connection = connect.Connect()
server_message = message.server_message(connection._ws)
chat = messageHandler.MessageHandler(server_message)
此类使用connect.Connect():
打开与websocket的连接class Connect:
def __init__(self):
self._ws = create_connection(config.server['ws-server'])
类server_message处理来自服务器的响应
class server_message:
def __init__(self, ws):
self.ws = ws
def recv_message(self):
return self.ws.recv()
现在产生错误的代码片段在Message_Handler类中,该类应该接受服务器响应,识别它的第一位并将其放入多处理中.Queue
class MessageHandler():
def __init__(self, server_message):
self.server_message = server_message
self.processes = {}
self.queues = {}
while(True):
received_message = self.server_message.recv_message()
self.sort_message(received_message)
有问题的部分是这个实现多处理的函数。进程:
elif((queueName in self.queues) == False):
q = multiprocessing.Queue()
q.put(received_message)
self.queues[queueName] = q
p=multiprocessing.Process(target=self.empty_queue, args=(q,))
self.processes[queueName] = p
self.processes[queueName].start()
print(self.processes[queueName])
def empty_queue(self, queue):
print("went good until here")
如果我启动程序,我会得到以下输出:
<Process(Process-1, started)>
went good until here
connection aborted error win error 10053 an established connection was aborted by the software in your host machine
回溯看起来像这样
File "C:/Users/Martin/PycharmProjects/ps-battle-bot/main.py", line 19, in <module>
chat = messageHandler.MessageHandler(server_message)
File "C:\Users\Martin\PycharmProjects\ps-battle-bot\messageHandler.py", line 16, in __init__
received_message=self.server_message.recv_message()
File "C:\Users\Martin\PycharmProjects\ps-battle-bot\message.py", line 8, in recv_message
return self.ws.recv()
File "C:\Python33\lib\site-packages\websocket\__init__.py", line 710, in recv
opcode, data = self.recv_data()
File "C:\Python33\lib\site-packages\websocket\__init__.py", line 725, in recv_data
frame = self.recv_frame()
File "C:\Python33\lib\site-packages\websocket\__init__.py", line 800, in recv_frame
self._frame_header = self._recv_strict(2)
File "C:\Python33\lib\site-packages\websocket\__init__.py", line 931, in _recv_strict
bytes = self._recv(shortage)
File "C:\Python33\lib\site-packages\websocket\__init__.py", line 913, in _recv
bytes = self.sock.recv(bufsize)
从错误消息判断它似乎是websocket的某种问题,但我无法弄明白。 对不起,大量的代码,但谷歌搜索根本没有帮助,错误信息是非常无意义的。 我在使用python 3.3.2的Windows x64上