Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to make a SimpleXMLRPCServer abort at CTRL-C under windows

Reply
Thread Tools

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

 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      02-13-2010
On Fri, 12 Feb 2010 22:36:42 -0300, "Gabriel Genellina"
<(E-Mail Removed)> declaimed the following in
gmane.comp.python.general:

>
> 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\runpy.py", line 122, in _run_module_as_main
> "__main__", fname, loader, pkg_name)
> File "d:\apps\python26\lib\runpy.py", line 34, in _run_code
> exec code in run_globals
> File "d:\apps\python26\lib\SimpleXMLRPCServer.py", line 615, in <module>
> server.serve_forever()
> File "d:\apps\python26\lib\SocketServer.py", line 224, in serve_forever
> r, w, e = select.select([self], [], [], poll_interval)
> KeyboardInterrupt
>

Well... Okay, maybe not a full console I/O request but I suspect
code that didn't use select() might also be non-responsive -- while
select() only works with sockets on Windows, it may include a check for
<ctrl-c>... code that doesn't invoke such an event-based wait, though?
--
Wulfraed Dennis Lee Bieber KD6MOG
http://www.velocityreviews.com/forums/(E-Mail Removed) HTTP://wlfraed.home.netcom.com/

 
Reply With Quote
 
 
 
 
News123
Guest
Posts: n/a
 
      02-13-2010
Hi Gabriel,




News123 wrote:
> Hi Gabriel,
>
> Gabriel Genellina wrote:
>> En Fri, 05 Feb 2010 20:03:51 -0300, News123 <(E-Mail Removed)> escribió:
>>
>>> I'm using an XMLRPC server under Windows.
>>>
>>> What I wonder is how I could create a server, that can be killed with
>>> CTRL-C
>>>
>>> The server aborts easily with CTRL-BREAK but not with CTRL-C (under
>>> Windows)
>>>
>>> If I press CTRL-C it will only abort when the next RPC call occurs.
>>> It seems it is blocking in the select() call in the handle_request()
>>> function.

>> Python 2.6 and up behaves exactly as you want.
>> On previous versions you may use this:
>>
>> class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServ er):
>>
>> ... your methods ...
>>
>> if not hasattr(SimpleXMLRPCServer.SimpleXMLRPCServer, 'shutdown'):
>>
>> # pre 2.6
>> quit = False
>>
>> def serve_forever(self):
>> while not self.quit:
>> self.handle_request()
>>
>> def shutdown(self):
>> self.quit = True
>>
>> def server_bind(self):
>> self.socket.settimeout(1.0)
>> SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind( self)
>>

>
> Overloading server_bind() with your version solved my problem.
>


Overloading server_bind() makes the server killable with ctrl-C.

I noticed however, that I can't use this as solution.
If the bind function sets a time out, then it seems,

that there are regular small time windows, when connecting clients fail.
I don't have the error message any more, but will post it when I capture
the event next time.


bye

N

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Abort SimpleXMLRPCServer request prematurely? Joseph Turian Python 0 06-29-2009 05:52 AM
SimpleXMLRPCServer runnning as a Windows Service using win32serviceutil JDF Python 0 04-26-2006 04:54 PM
Re: Make SimpleXMLRPCServer Require Auth? John Abel Python 0 10-12-2005 03:11 PM
Make SimpleXMLRPCServer Require Auth? John Abel Python 0 10-12-2005 07:56 AM



Advertisments