Can't catch CTRL-C when SimpleXMLRPCServer running ?

shearichard at gmail.com shearichard at gmail.com
Wed Feb 20 23:03:54 EST 2013


Hi - I have a script which instantiates a SimpleXMLRPCServer server and which I use to simulate a 'real server' when developing client scripts which will eventually get used with the 'real server'.

I would like to stop the script running in response to a CTRL-C.

The script is run on windows.

The script looks like this ...

from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimulateCRRWebServices import SimulateCRRWebServices
import signal
import sys
#Set up signal handler
def signal_handler(signal, frame):
	print 'Closing down now'
	sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)
#Set up XMLRPC Server
server = SimpleXMLRPCServer(('localhost', 42001), logRequests=True)
server.register_introspection_functions()
server.register_multicall_functions()
server.register_instance(SimulateCRRWebServices())
#Off we go ...
print 'Use Control-C to exit'
server.serve_forever()

... the trouble the script is unable to see my CTRL-C's !

As a reference I've written another script which *does* catch CTRL-C's ...

import signal
import sys
def signal_handler(signal, frame):
	print 'You pressed Ctrl+C!'
	sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
print 'Press Ctrl+C'
while True:
	continue

... so is there a way around this ?


Be grateful for any advice.









More information about the Python-list mailing list