TCP servers in Python - two processes want to use same port

Peter Hansen peter at engcorp.com
Mon Feb 23 11:04:29 EST 2004


Pif Paf wrote:
> 
> The child process is a very simple program using SimpleHTTPServer. The
> problem is when I run my test harness, break it with Ctrl-C then try to
> run it again. The http server complains that it cannot bind to the socket,
> as the address is already in use.

I believe you should be looking at SO_REUSE_ADDR as a means of rebinding
to a socket that was just used recently and may still be active at the 
OS level, even if the app that used it has exited.

As for the specific question about ways to kill the app that is listening
on a socket already: I think if you don't know which app it is, there
isn't a clean way to find out.  If you do know, though, as your test 
harness probably does, can't it just "kill -9" the thing?

-Peter



More information about the Python-list mailing list