[Tutor] seeking help to a problem w/ sockets
Kent Johnson
kent37 at tds.net
Sun Apr 27 13:18:01 CEST 2008
James Duffy wrote:
> I have a problem w/ a file transfer receiver. They way it works is it
> binds a port for incoming transfer , when the file transfer is complete.
> It closes the connection and the socket, then loops back and restarts
> the bind and listen. I have it set so that the socket is reuseable,
> which is why this works. However, if the program that is using this
> function is closed while listening, it appears that it does not
> ”un-bind” because when the program is reopened and a listen attepted to
> start I get a “port already in use” error. Only a reboot fixes this
> issue. This code is imported into a main GUI script. We have it set to
> execute some cleanup functions on exit, I need a function that can dig
> down to the thread the listener is running in, stop the listen and close
> the connection and socket. I basically need to get to the close function
> and then stop the while loop.
The usual way to terminate a thread from another thread is to set a flag
that the running thread checks periodically. Here is an example:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65448
This discussion may be helpful:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/7f116836f1fd2805/6adcc7e371238fdd?lnk=gst
Kent
More information about the Tutor
mailing list