At Monday 22/1/2007 14:49, alessandro wrote:

Oh my God! it's really so complicated?

3 modules (threading, SocketServer, select) only for design a way to
shutdown a TCP server????
...but they told me that python was easy... :)

You already have the answer: replace serve_forever with your own loop.

I'm working on a simulator and I have a monitor server that collects
information. I can shutdown it using Ctrl-C from the keyboard but for
my purpose could be very nice if I introduce a timer. So I could launch
my monitor like this:
./monitor 100

and my monitor will run for 100 seconds. For this I'm using the Timer

This is simple enough, I presume:

  try:
    stopt = time.time()+100
    while time.time()<stopt:
        server.handle_request()
  except KeyboardInterrupt: pass
  # shutdown

The drawback is that it won't leave the loop until a request arrives, but this may not be a problem for you. (Other suggestions are more complicated because of this issue.)


--
Gabriel Genellina
Softlab SRL

        

        
                
__________________________________________________ Preguntá. Respondé. Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to