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

Chris Reay mrchameleon at hotmail.com
Sun May 26 19:59:25 EDT 2002


Irmen de Jong <irmen at USENET_NOSPAM_REMOVETHISxs4all.nl> wrote in message news:<acra53$k92$2 at news1.xs4all.nl>...
> 
> I was recommended to use asyncore/Medusa (that doesn't use threads at all).
> But since my system (Pyro) is currently structured around threads, that
> would require a major rewrite.
> 
> So I optimized my thread solution: don't use a thread per request, just
> spawn a new thread and let it live. The main loop only handles new
> accept()s. First results show a speed increase of up to 2 times :)
> 
> Irmen

Hi Irmen

My own multiple server class is unthreaded. It has separate methods
for accepting new connections, for reading, for writing, and for
closing "dead" connections. The reading method uses select with a
timeout of 0 ie:

readList, w, e = select(self.clientList, [], [], 0)

The method then reads each client's data completely, one by one. This
method seems to work quickly, simply, and well.

Hth, fwiw

Chris



More information about the Python-list mailing list