Making sure script only runs once instance at a time.

MonkeeSage MonkeeSage at gmail.com
Mon Oct 2 19:45:48 EDT 2006


Here's a class using Fredrik's suggestions to provide generic,
cross-platform file locking (only tested on *nix however, with the two
test files listed [i.e., run test1.py in one terminal then test2.py in
another]):

http://pastie.caboo.se/15851

Ps. The lockfile should also always be cleaned up (even when your
program excepts) because of the magic __del__ method, but I don't
guarentee it will be (nor depend on it: I used the pid + hostname in
the lockfile approach).

Regards,
Jordan




More information about the Python-list mailing list