non-blocking sockets

Donn Cave donn at u.washington.edu
Tue Apr 23 18:08:10 EDT 2002


Quoth kevin at cazabon.com (Kevin Cazabon):
| 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.

Why not?
 - Threads aren't universally portable?
 - On platforms with threads, sockets don't universally support
   concurrent read and write?
 - the thread interlocks over the read buffer are more work than
   the select() single-threaded solution?
 - it's even more complicated if there are multiple inputs?
 - there's no obvious way to tell a thread to quit, when it's
   blocking on a socket read?
 - select() also allows the program to happily do other stuff as
   long as it doesn't need data, and it naturally supports multiple
   inputs?

There's probably more, as I haven't used threads this way enough to
have run into all the problems.  It can be done, and I'm sure if you
know what you're doing, it works out fine, but since you asked ...

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list