up vote 25 down vote favorite
22
share [g+] share [fb] share [tw] |
Is there a Pythonic way to have only one instance of a program running? The only reasonable solution I've come up with is trying to run it as a server on some port, then second program trying to bind to same port - fails. But it's not really a great idea, maybe there's something more lightweight than this? (Take into consideration that program is expected to fail sometimes, i.e. segfault - so things like "lock file" won't work) Update: the solutions offered are much more complex and less reliant than just having a port occupied with a non-existent server, so I'd have to go with that one.
python singleton locking
|
||||||||||||
add comment |
|||||||||||||
start a bounty
|
10 Answers
up vote 22 down vote accepted
|
The above code should do the job, it is cross-platform and runs on Python 2.4-3.2. I tested it on Windows, OS X and Linux.
The latest code version is available singleton.py. Please file bugs here. You can install tend using one of the following methods:
|