我想在python 2.7中使用Twisted編寫客戶端。我的代碼在linux(debian squeeze)中工作得很好,但是當我在windows(xp和7)上嘗試它時,我得到了一串不斷的錯誤消息。這些消息的截圖是here。Python Twisted addReader在linux下工作,但不是windows
我縮小了錯誤,並能寫出我的客戶的一個非常精簡版仍然包含錯誤:如果包含「reactor.addReader(測試)」行註釋掉
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()
出來,我沒有收到任何錯誤消息。如果我在linux上運行此代碼而不註釋掉任何行,則不會收到任何錯誤消息。
我發現this question,我不認爲它有同樣的問題,但如預期的那樣,它在Windows上無法正常工作。
這段代碼是否正確,這是一個Windows錯誤,還是我必須做不同的事情才能在Windows中工作?
我想讀取IO,特別是我使用curses,並根據[此文件](http://twistedmatrix.com/trac/browser/trunk/doc/core/examples/cursesclient.py?rev = 24576),fileno函數應返回0(sys.stdin.fileno()== 0)。就像我在問題中所說的那樣,這對我來說是linux的工作,但它聽起來像windows選擇只支持套接字可能是問題。 – Matt 2012-07-31 11:15:32
是的。您無法使用Windows上的「SelectReactor.addReader」從標準輸入中讀取數據。 – 2012-07-31 13:57:48
這不是你唯一的問題。 ncurses模塊在Windows上不可用,所以即使你有這個工作,它也無濟於事。參見http://docs.python.org/library/curses.html#module-curses - 它說「Platforms:Unix」。 – Glyph 2012-08-01 21:15:23