problem with SocketServer -- address already in use
Gordon McMillan
gmcm at hypernet.com
Tue Jul 13 18:32:51 EDT 1999
Phil Hunt wrote:
> I'm trying to use SocketServer.py to write a TCP server. I ran
> my program with ``python serv.py'', which went into an infinite loop
> (which is what it should do). I exited my program with ^Z, and tried
> to start it up again. I got an error message:
>
> socket.error: (98, 'Address already in use')
>
> which I presume is because something thinks the old invokation of my
> program is still using port 7070.
>
> How do I clear the port, before I start up my server?
Three non-exclusive optons:
1) Wait. It will eventually go away.
2) Use a try:... finally: ... and close the bound socket in the
finally clause.
3) Before binding the socket, use setsockopt(SOL_SOCKET,
SO_REUSEADDR, 1)
Once it has happened, (1) is your only viable alternative.
- Gordon
More information about the Python-list
mailing list