我正在尝试使用 Twisted 在 python 2.7 中编写客户端。我的代码在 linux(debian 挤压)中工作得很好,但是当我在 windows(xp 和 7)上尝试它时,我收到了源源不断的错误消息流。这些消息的屏幕截图在这里。
我已经缩小了错误范围,并且能够编写一个仍然包含错误的客户端的非常精简的版本:
from twisted.internet.protocol import Protocol,ClientFactory
from twisted.protocols.basic import LineReceiver
from twisted.internet import reactor
class TheClient(LineReceiver):
def lineReceived(self,line):
print line
def connectionLost(self,reason):
reactor.stop()
class TheFactory(ClientFactory):
protocol = TheClient
class Test(object):
def doRead(self):
pass
def fileno(self):
return 0
def connectionLost(self,reason):
print 'connection lost'
def logPrefix(self):
return 'Client'
def main():
print 'starting'
test = Test()
reactor.addReader(test)
reactor.run()
if __name__ == '__main__':
main()
如果包含“reactor.addReader(test)”的行被注释掉,我不会收到任何错误消息。如果我在 linux 上运行此代码而不注释掉任何行,我不会收到任何错误消息。
我发现了这个问题,我认为它不是同一个问题,但正如预期的那样,它在 Windows 上无法正常运行。
这段代码是否正确,这是一个 Windows 错误,还是我必须做一些不同的事情才能让它在 Windows 中工作?