Inhibiting duplicate apps in Windows?

Peter Hansen peter at engcorp.com
Fri Jun 21 01:42:34 EDT 2002


Cliff Wells wrote:
> 
[on locks 'n such]
> A fairly fool-proof/portable method is to open a socket. If the app is
> run a second time it will fail on the attempt.  Even if the app crashes,
> the socket will be closed by the OS (although it may take a couple of
> seconds on occasion).

Interesting, although I take it you mean "bind a socket to a port".
Are there any complications with this?  I created one and it's true
another instance could not be opened ("address already in us") but
the socket is listed with "netstat" as being LISTENING even though
I have not called listen() or accept().  Any problems with doing 
that, if something connects to the socket?  Could it cause the
socket to be held open for more than a couple of seconds after
closing?  Sometimes sockets can take minutes to be cleaned up.

-Peter



More information about the Python-list mailing list