how to make a SimpleXMLRPCServer abort at CTRL-C under windows

Gabriel Genellina gagsl-py2 at
Sat Feb 13 02:36:42 CET 2010

En Fri, 12 Feb 2010 11:22:40 -0300, Aahz <aahz at> escribió:

> In article <mailman.2422.1265961504.28905.python-list at>,
> Dennis Lee Bieber  <wlfraed at> wrote:
>> On 11 Feb 2010 21:18:26 -0800, aahz at (Aahz) declaimed the
>> following in gmane.comp.python.general:
>>> In article <mailman.2077.1265524158.28905.python-list at>,
>>> Gabriel Genellina <gagsl-py2 at> wrote:
>>>> Strange. With Python 2.6.4 I don't need to do that; I'd say the  
>>>> difference
>>>> is in the OS or antivirus (some AV are known to break the TCP stack).
>>> Perhaps, but I've also found that ctrl-C doesn't work on Windows.
>> 	Unless the running program makes an I/O call to the console, I don't
>> think <ctrl-c> gets past the device driver... <G>
> That's probably it.  It's more annoying for me because I run Windows with
> a VM on a Mac, which doesn't have ctrl-break.

On a "real" PC with Windows XP SP3 and Python 2.6.4, with an idle server,  
just hitting Ctrl-C was enough:

D:\temp>python -m SimpleXMLRPCServer
Running XML-RPC server on port 8000
Traceback (most recent call last):
   File "d:\apps\python26\lib\", line 122, in _run_module_as_main
     "__main__", fname, loader, pkg_name)
   File "d:\apps\python26\lib\", line 34, in _run_code
     exec code in run_globals
   File "d:\apps\python26\lib\", line 615, in <module>
   File "d:\apps\python26\lib\", line 224, in serve_forever
     r, w, e =[self], [], [], poll_interval)

A slightly more realistic example: a busy, single threaded server. I had  
to hit Ctrl-C twice: the first time, KeyboardInterrupt was sent as a Fault  
response to the client.

import sys

def busy():
     x = 50000
     y = x**x
     return "Ok"

if sys.argv[1]=='server':
     import SimpleXMLRPCServer
     server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost",  
   import xmlrpclib
   proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
   while True:
     print "client", proxy.busy()

Maybe the OP's code containes a bare 'except:' clause that swallows  
KeyboardInterrupt, or the server is so busy that is always executing a  
function handler (and all KeyboardInterrupt become Fault and are sent as a  
function response).

Mmm, perhaps that's a bug, a KeyboardInterrupt should bubble up to the  
server code, not being treated as an error in computing the function  

Gabriel Genellina

More information about the Python-list mailing list