[Tutor] Threading + socket server (blocking IO)
Kent Johnson
kent37 at tds.net
Mon Feb 6 12:11:17 CET 2006
Liam Clarke wrote:
> Hi all,
>
> About to embark on my first foray into threading, and rather unsure of
> initial approach. I have a basic UDPServer from SocketServer running
> using serve_forever(). I'd like to stick this in a thread where it can
> endlessly loop waiting for incoming packets, and pushing the received
> data into a list where it can be retrieved and operated on by another
> thread, until such time as the controlling app terminates it.
Threaded servers are supported by the standard library. Instead of using
UDPServer use this class:
class ThreadingUDPServer(ThreadingMixIn, UDPServer): pass
Then your request handler will be called in a separate thread. You don't
need to queue the requests yourself, the server will create the thread
and dispatch to it when a request is received.
Kent
More information about the Tutor
mailing list