Bidirectional Networking

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Dec 12 16:04:14 EST 2008


En Fri, 12 Dec 2008 15:22:34 -0200, Emanuele D'Arrigo <manu3d at gmail.com>  
escribió:

> Thank you both for the suggestions! Eventually I tried with threading
> as illustrated in the code below.
> And it works pretty well! The only problem I'm having with it is that
> as the server is a daemon the program should end when the client
> thread cease to be alive. But it doesn't seem to work that way and I'm
> not sure what's going on! I did achieve my objective though. Two
> separate instances of the code below will happily send random numbers
> to each other for a few seconds!

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.
Python 2.6 has a shutdown() method for the same purpose.

-- 
Gabriel Genellina




More information about the Python-list mailing list