signal handling oddity
Justin Johnson
justinjohnson at fastmail.fm
Mon Jun 9 09:47:16 EDT 2003
Hi,
I have an xmlrpc server and I'd like to be able to catch control-c and
cause the server to exit. Without any special signal code it just keeps
running and doesn't handle control-c at all. I tried adding code to
handle SIGINT (below). What happens now is, I control-c and nothing
happens, but when the next xmlrpc request comes through, the service
exits, running stopService. So the control-c is caught, but only when
the next request comes through. Anyone know why this is?
Thanks.
-Justin
[snip]
def startService():
# Make sure we can catch a Ctl-C to shutdown the service
signal.signal(signal.SIGINT, stopService)
# Startup the service. Note, we specify our own request handler so that we can handle basic auth,
# allowing us to password protect the service. See myxmlrpc.py for more info.
server = SimpleXMLRPCServer.SimpleXMLRPCServer((config.thisServer, config.portNumber), BasicAuthXMLRPCRequestHandler)
server.register_instance(CCService())
server.serve_forever()
def stopService(sigNum, stackFrame):
print "Exiting... bye bye!"
sys.exit()
if __name__ == '__main__':
startService()
[/snip]
More information about the Python-list
mailing list