Can't catch CTRL-C when SimpleXMLRPCServer running ?

S

shearichard

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.
 
R

Roland Koebler

Hi,
I would like to stop the script running in response to a CTRL-C.
how about "KeyboardInterrupt"?

try:
...
except KeyboardInterrupt:
print "You pressed Ctrl+C"


Roland
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top