Handling more than one request on a socket

Jeff Grimmett grimmtoothtoo at yahoo.com
Thu Aug 30 03:42:24 CEST 2001


<brueckd at tbye.com> wrote in message news:<mailman.999058347.5355.python-list at python.org>...

> With threads, it goes something like this (untested):

Thanks; since eventually I'll have to contend with threads in the
rough, I'm sure, I'll just snip it and stash it away as a nice
starting point :-)

> That's about it - you can put whatever you want in handler of course.
> Also, there's some great code to do all this in the SocketServer module,
> including a mixin class that makes it very easy to do all of the above for
> you (this newsgroup had a thread on this very topic within the last week).

After figuring out my goofs in the original socket code, I looked into
SocketServer.  Was able to put up a telnet server after an hour and a
half of puzzling over the source code (the documentation really didn't
give me a handle on it, but the source is well-documented). Me, one of
my kids, and my wife spend a few minutes merrily pounding keyboards on
three sessions without a hiccup. Of course, the acid test will come
when I get file transfers working through it the embryonic code I have
:-)

Anyway, you're right, it makes it all a snap.

> To handle multiple connections without threads (which may be a good idea
> if you need a higher performance solution and are mostly I/0 bound, like
> if you're writing an HTTP proxy server), you can use the poll call in the
> select module (I think this was added in Python 2.0.

Alas, I'm writing this to work on both Linux and Win32 so I'm
constrained by what isn't available on W32, and the poll object is one
of the things labeled "UNIX ONLY" in the docs. Alas.

> Like I said, this approach works well for higher performance stuff, but is
> a little more involved and makes you approach the problem from a slightly
> different angle.

It's actually the angle I wanted to use, since the old C code I'm
basing all this off of went that route (in a less feature-rich
environment).

Thanks!



More information about the Python-list mailing list