SocketServer and timers

bryanjugglercryptographer at yahoo.com bryanjugglercryptographer at yahoo.com
Fri Jul 28 01:17:06 EDT 2006


alf wrote:
> I have one thread app using SocketServer and use server_forever() as a
> main loop. All works fine, but now I need certain timer checking let's
> say every 1 second something and stopping the main loop. So questions are:
> 	-how to stop serve_forever

Override serve_forever() and replace "while 1:" with something like
"while self.continue_flag:".

> 	-how to implement timers

You could override get_request(), and use select.select() to wait for
either the socket to become readable (so the accept() won't block), or
a timeout to expire. If you are not already, use the threading or
forking
mixin so that the request handler won't stop everthing if it blocks.


-- 
--Bryan




More information about the Python-list mailing list