__del__ pattern?

Michael Hudson mwh at python.net
Tue Aug 16 20:21:34 EDT 2005


bryanjugglercryptographer at yahoo.com writes:

> Chris Curvey wrote:
>> I need to ensure that there is only one instance of my python class on
>> my machine at a given time.  (Not within an interpreter -- that would
>> just be a singleton -- but on the machine.)  These instances are
>> created and destroyed, but there can be only one at a time.
>>
>> So when my class is instantiated, I create a little lock file, and I
>> have a __del__ method that deletes the lock file.  Unfortunately, there
>> seem to be some circumstances where my lock file is not getting
>> deleted.  Then all the jobs that need that "special" class start
>> queueing up requests, and I get phone calls in the middle of the night.
>
> For a reasonably portable solution, leave the lock file open.
> On most systems, you cannot delete an open file,

Uh, you can on unix -- what else did you have in mind for "most
systems"?

Cheers,
mwh

-- 
  Well, yes.  I don't think I'd put something like "penchant for anal
  play" and "able to wield a buttplug" in a CV unless it was relevant
  to the gig being applied for...                  -- Matt McLeod, asr



More information about the Python-list mailing list