Writing Multithreaded Client-Server in Python.
google at phaedro.com
google at phaedro.com
Thu Sep 1 18:54:49 CEST 2005
Steve Holden schreef:
> Paul Rubin wrote:
> > google at phaedro.com writes:
> >>What it doesn't do (and what Sidd seems to search as is suggested by
> >>his 'select()' remark) is handle each client in a separate thread.
> > I don't know what you mean by that. It launches a new thread for each
> > client connection. The connection is two-way and can last as long as
> > desired. If you're imagining something like a web server handling
> > http requests, using http 1.1 keepalive, you could handle any number
> > of requests in that connection.
> I suspect he was trying to say that BaseHTTPServer has no mechanism for
> handling state. As you know, of course, this is most relevant across
> multiple successive connections to a server from the same client, and
> has little to do with threads.
see below: I must apologize for not being able to use the standard CS
vernacular but indeed I meant session (persistent state over multiple
requests) - I still think that the thread-starter looks for a mechanism
that handles each *session* in a thread where the 'mother'
server-thread selects the thread belonging to a session.
> >>If you want to apply SocketServer such that each client corresponds to
> >>one thread that handles its' requests (and maintains its state), don't
> >>use ThreadingMixIn - only the thread-selection will be executed in a
> >>separate thread.
> > What do you mean by "each client"? If a client connects, does some
> > stuff, disconnects, and later reconnects, how do you know that it's
> > the same client that's come back?
> The assertion that ThreadingMixIn doesn't handle *sessions* might be
> more appropriate, but then there's no reason why it really should (since
> if they were handled at all they would be better handled in the base
> server classes). By "each client" I suspect the OP really meant "each
> session", and was ignoring the fact that the same client can have
> multiple sessions to the same server.
Correct. My own 'brew' is multi-session-clients enabled (in fact I test
with two applets from the same PC) but indeed I used confusing language
saying 'client' for 'session'.
Again: ThreadingMixIn doesn't give you 'session threads' in which you
store persistent information - a candidate for some generic extension
of SocketServer ?
When doing research for my own hobby project, I stumbled upon "Twisted"
, it seems to give a lot in terms client-server features/functionality
compared to SocketServer ? Is it indeed a 'generic network programming
framework'? Anyone has experience with it ?
Thijs - phaedro.com
More information about the Python-list