Can select() be used with files in Python under Windows?

前端 未结 3 960
情话喂你
情话喂你 2020-12-06 07:07

I am trying to run the following python server under windows:

\"\"\"
An echo server that uses select to handle multiple clients at a time.
Entering any line          


        
相关标签:
3条回答
  • 2020-12-06 07:39

    Look like it does not like sys.stdin

    If you change input to this

    input = [server] 
    

    the exception will go away.

    This is from the doc

     Note:
        File objects on Windows are not acceptable, but sockets are. On Windows, the
     underlying select() function is provided by the WinSock library, and does not 
    handle file descriptors that don’t originate from WinSock.
    
    0 讨论(0)
  • 2020-12-06 07:40

    Of course and the answers given are right... you just have to remove the sys.stdin from the input but still use it in the iteration:

    for s in inputready+[sys.stdin]:

    0 讨论(0)
  • 2020-12-06 07:46

    I don't know if your code has other problems, but the error you're getting is because of passing input to select.select(), the problem is that it contains sys.stdin which is not a socket. Under Windows, select only works with sockets.

    As a side note, input is a python function, it's not a good idea to use it as a variable.

    0 讨论(0)
提交回复
热议问题