From: News123 on
Hi,



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.

Is there any trick, which I overlook?

thanks in advance for ideas and bye


N
From: Gabriel Genellina on
En Fri, 05 Feb 2010 20:03:51 -0300, News123 <news123(a)free.fr> 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.SimpleXMLRPCServer):

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

--
Gabriel Genellina

From: News123 on
Hi Gabriel,



Gabriel Genellina wrote:
> En Fri, 05 Feb 2010 20:03:51 -0300, News123 <news123(a)free.fr> 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:]



I', using python 2.6.4 nd neither on Win-XP nor on Win-7 I'm capable to
abort with CTR-C ?


On Linux however I can use CTRL-C .


>
> class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer):
>
> ... 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)
>


I tried something similiar, but without setting the socket timeout.
I'll try it now with.


N

From: News123 on
Hi Gabriel,

Gabriel Genellina wrote:
> En Fri, 05 Feb 2010 20:03:51 -0300, News123 <news123(a)free.fr> 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.SimpleXMLRPCServer):
>
> ... 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.

thanks again

N
From: Gabriel Genellina on
En Sat, 06 Feb 2010 21:24:33 -0300, News123 <news123(a)free.fr> escribi�:
> Gabriel Genellina wrote:
>> En Fri, 05 Feb 2010 20:03:51 -0300, News123 <news123(a)free.fr> 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
>>
>> Python 2.6 and up behaves exactly as you want.
>> On previous versions you may use this:
>>
>> def server_bind(self):
>> self.socket.settimeout(1.0)
>> SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self)
>>
>
> Overloading server_bind() with your version solved my problem.

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

--
Gabriel Genellina