OS independent way to check if a python app is running?

Dan Sommers somm1105 at bellsouth.net
Sun Dec 27 19:42:58 EST 2009


On Sun, 27 Dec 2009 19:07:12 -0500, python wrote:

> Hans,
> 
>> Unfortunately, Windows is not a respectable OS. Unlike Unix, it allows
>> two processes to bind to the same port. The theory is that this somehow
>> allows the two processes to share their workload. One thing the OP can
>> portably do, is try to connect() to the port. If that succeeds, then a
>> server program is already running at that port, so he should exit.
> 
> Thank you for your tip - spot on!

Beware of the converse, though.  If a process *cannot* connect to the 
port, then it should *not* assume that another server *isn't* running.  
If two potential servers both start at the same time, and each tries to 
connect, then both will fail, but you don't want both to start, either.




More information about the Python-list mailing list