how to do non-blocking I/O

J. Xu xu at reflexsecurity.com
Wed Mar 17 22:09:56 CET 2004


I am a newbie to python. I am writing a client application, I need to 
read query results from the server. Mostly I'll have a file object for 
the connection to the server. So I use read() or readline() to get the 
response. But since these are blocking calls, I have to use a seperate 
thread for the input reading. But then I have another problem, my input 
thread running in the following loop

while not quit:
    str = ins.readline()
    .... process the response

so I can't terminate the thread when it's blocking in the readline() 
until the connection is closed. So looks like I need to use non-blocking 
IO such as select() or poll(). But since I need this application to be 
cross-platform, and these are not well supported on Windows, I don't 
know what to do.





More information about the Python-list mailing list