[Tutor] Save me from this horrible kludge! (long)

alan.gauld@bt.com alan.gauld@bt.com
Mon, 14 May 2001 17:07:05 +0100


> deal. However, I want only one instance of the program 
> running at a time. I have solved this before by using 
> a temporary file as a lock.

Thats probably as good a way as any! Depending on your 
platform there are several issues/methods of doing this.

Windows (16 bit) makes it easy through the API but 32 
bit windows makes it much harder. You basically have to 
search for a program of the same name...

In Unix its harder still since more than one user might 
be on the machine and you might want to run one copy per 
user - in which case your lock-file is the easiest 
solution!

This was discussed on comp.lang.python newsgroup recently, 
you  might want to do a search on the archives (at Google 
say)

> the lockfile as it may not be easy to clean up if the program 
> terminates abnormally!

That's what try/finally is for ;-)
Not bulletproof but pretty reliable!

Alan G