non-blocking sockets

Kevin Cazabon kevin at cazabon.com
Tue Apr 23 17:04:21 EDT 2002


Why not use a separate thread to monitor the socket, and post an event
when data is read from the socket and available to the rest of the
program?  This way, the socket thread can block all it wants, as its
only job is to monitor for incoming data, and the rest of your program
can happily do other stuff in the meantime.

Kevin Cazabon.



so very tired <g0riaman at cdf.toronto.edu> wrote in message news:<Pine.GSO.4.30.0204222138510.19452-100000 at eddie.cdf>...
> When trying to read from a socket, I don't want it hanging, so I set it to
> non-blocking by calling
> 
> setblocking(0)
> 
> but then when I try to read from it and there is no data in the socket, I
> get an error. I tried this in both windows and linux and in both I get an
> error and the program stops. It says there's an exception but it doesn't
> say the name of the exception so I can't even try to catch.
> Does anyone know how I can check if there's data coming from a socket
> connection without hanging or having the program barf on me?
> Thanks.
> mRiaz



More information about the Python-list mailing list