Bidirectional Networking

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Dec 13 23:10:41 EST 2008


En Sat, 13 Dec 2008 13:03:17 -0200, Emanuele D'Arrigo <manu3d at gmail.com>  
escribió:
> On Dec 12, 9:04 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> wrote:
>> If you're using 2.5 or older, override serve_forever:
>>
>>      def serve_forever(self):
>>          while not getattr(self, 'quit', False):
>>              self.handle_request()
>>
>> and set the server 'quit' attribute to True in response to some command
>>  from the client.
>
> Ok, I've tried this method and it would work if I wanted to shut down
> the server from the remote client. But if I want the server to shut
> down from the server itself upon some condition it doesn't work
> because the while statement is evaluated again only after there has
> been a request. If requests are infrequent or have ceased the

Yes, this is the problem with this simple approach, handle_request is  
blocking. Python 2.6 has great improvements on this situation.

> The problem was that in my code I used:
>
> asyncServer.daemon = True
>
> but somehow that doesn't work. I then tried:
>
> asyncServer.setDaemon(True)
>
> and that does work:

daemon became a property in Python 2.6; setDaemon was the only way to set  
it in previous versions.

> Thanks for your help!

Thanks for sharing your code!

-- 
Gabriel Genellina




More information about the Python-list mailing list