socket.accept()
Jeethu Rao
jeethur at sancharnet.in
Tue Feb 11 23:44:02 EST 2003
Marco,
The simplest solution would be to have a threading.Event
for signaling the shutdown of the application. then,
have a method set the Event and connect to the server
from the other thread and just close it. This makes the server
come out of the accept() call, Now you can check for the shutdown
event.
Here is the a snip from my code, the shutdown function of the
Server class
def shutdown(self):
self.die.set() # self.die is the event
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((Globals.ServerHostName,Globals.ServerPort))
s.close()
self.pool.shutdown()
And change you run() code to something like
> def run():
> mysocket = socket.socket(blabla)
> mysocket.bind(blabla)
> mysocket.listen(1)
> while 1:
> newsocket, addr = mysocket.accept()
if self.die.isSet():
break
> # and so on...
Hope this helps
Jeethu Rao
More information about the Python-list
mailing list