[ python-Feature Requests-1193577 ] add server.shutdown() method and daemon arg to SocketServer

SourceForge.net noreply at sourceforge.net
Tue May 3 15:31:17 CEST 2005


Feature Requests item #1193577, was opened at 2005-05-01 22:04
Message generated for change (Settings changed) made by montanaro
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1193577&group_id=5470

>Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: paul rubin (phr)
>Assigned to: Skip Montanaro (montanaro)
Summary: add server.shutdown() method and daemon arg to SocketServer

Initial Comment:
First of all the daemon_threads property on socket
servers should be added as an optional arg to the
server constructor, so you can say:
     TCPServer(..., daemon_threads=True).serve_forever()

instead of

    temp = TCPServer(...)
    temp.daemon_threads=True
    temp.serve_forever

Secondly there should be a way to STOP the server, once
you've started serving forever!  A request handler
should be able to say

   self.server.stop_serving()

This would work by setting a flag in the server object.
 The serve_forever loop would use select with a timeout
(default 0.5 sec, also settable as an optional arg to
the server constructor) or alternatively set a timeout
on the socket object.  So it would block listening for
new connections, but every 0.5 sec it would check the
stop_serving flag and break out of the loop if the flag
was set.

This method was suggested by Skip Montanaro in a clpy
thread about how to stop SocketServer and it's useful
enough that I think it should be part of the standard
impl.  I can make a patch if it's not obvious how to do it.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1193577&group_id=5470


More information about the Python-bugs-list mailing list