Socket Blocking problem

Andrew Bennetts andrew-pythonlist at puzzling.org
Fri Jan 3 05:51:39 EST 2003


On Fri, Jan 03, 2003 at 10:04:28AM +0000, sree wrote:
> Hi guys
> 
> I am writing a small socket program in python. Here there are two progs. One
> sits on system A and accepts connections, does something with the data that
> came in. Othe sits on system B and sends commands to system A. Problem is I
> want to be able to read if system A is busy or free from system B. Hence I
> tried setblocking(0) but then it fails to start with error as below on
> system A.

[lengthy description of gory details skipped]

Non-blocking socket operations are tricky to get right, there's a few fair
nasty little cases that can bite you (which are real socket errors and which
are simply due to the socket being busy?).  I'd recommend using a library
like Twisted <http://twistedmatrix.com/> to make your life easier -- in
fact, Twisted does a lot more than just simply non-blocking I/O.  There's
also asyncore, but Twisted is alot simpler and more powerful... let me know
if you have any problems with it.

Regards,

-Andrew.






More information about the Python-list mailing list