Eli提供了一个通用示例,说明如何在线程内管理套接字客户机,并与队列模块通信到主作用域。(再次感谢伊莱!)在
一个线程工作得很好,但是我试图同时管理多个SocketClientThread对象。在
连接之后,当我试图向第二个对象发送数据时,它告诉我插座ClientThread.socket没有sendall属性,所以我认为套接字会被清空。在
1和2的服务器都成功地接收到连接,但触发错误的是第二台服务器的send命令。在
如何在多个对象中重用这个类?在
输出如下:$ python testmodule.py
('sct1: ', 1, None)
('sct1: ', 1, 'tuxy')
('sct2: ', 1, None)
Exception in thread Thread-2:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py", line 522, in __bootstrap_inner
self.run()
File "testmodule.py", line 59, in run
self.handlers[cmd.type](cmd)
File "testmodule.py", line 115, in _handle_SEND
self.socket.sendall(header + cmd.data)
AttributeError: 'NoneType' object has no attribute 'sendall'
下面是我试图打开两者的代码:
^{pr2}$