Python Twisted addReader works on Linux but not windows

I am trying to write a client in python 2.7 using Twisted. My code works fine on linux (debian squeeze), but when I tried it on windows (xp and 7), I got a constant stream of error messages. A screenshot of these messages is here .

I narrowed down the error and was able to write a very stripped-down version of my client that still contains the error:

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() 

If the line containing 'reactor.addReader (test)' is commented out, I do not receive any error messages. If I run this code on Linux without commenting on any lines, I do not receive any error messages.

I found this question , I do not think its the same problem, but, as expected, it did not function properly in the windows.

Is this code correct and is it a bug in Windows, or do I need to do something different to work in windows?

+4
source share
1 answer

The Windows select implementation only supports sockets. Presumably, file descriptor 0 in your process does not represent a socket. Most likely, this is something related to standard I / O.

If you just want to use standard I / O, then twisted.internet.stdio , although you may run into some rough edges with it on Windows (error messages and corrections are appreciated!).

If you are not interested in standard I / O, and 0 is just an arbitrary test, you will probably need to decide which input you are trying to make in particular. Depending on what type of file descriptor you have, there will probably be a different approach to successfully reading from it.

+2
source

All Articles