Sockets/select: how to deal with multiple connections in threads?

Kragen Sitaker kragen at pobox.com
Tue May 28 01:28:24 EDT 2002


Irmen de Jong <irmen at USENET_NOSPAM_REMOVETHISxs4all.nl> writes:
> main loop uses select() on the current connection list.
> if a new connection arrives, add this new socket to the connection list.
> if data is available on a socket, spawn a new thread to read the data.

My suggestions:

First, use asyncore.  Second, don't accept() or read() or write() or
send() or recv() data in any thread but the thread that runs the
select() loop --- when data is available on a socket, don't spawn a
new thread to read it, just read it (and spawn a new htread if
necessary to handle it, or pass it to an existing thread).




More information about the Python-list mailing list