signal handling oddity

Justin Johnson justinjohnson at
Mon Jun 9 15:47:16 CEST 2003


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?


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 for more info.
	server = SimpleXMLRPCServer.SimpleXMLRPCServer((config.thisServer, config.portNumber), BasicAuthXMLRPCRequestHandler)

def stopService(sigNum, stackFrame):
	print "Exiting... bye bye!"

if __name__ == '__main__':

More information about the Python-list mailing list