Inhibiting duplicate apps in Windows?

Cliff Wells logiplexsoftware at earthlink.net
Fri Jun 21 03:39:20 EDT 2002


On Thu, 2002-06-20 at 22:42, Peter Hansen wrote:
> 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".

Uh, yeah, sorry to be ambiguous.

> 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.

You know, I haven't actually tested such a situation, but I don't think
another program can connect to that socket without accept() being called
(but I could be wrong).  Probably best just to try it an find out.


Cliff






More information about the Python-list mailing list