Singleton process
Cameron Laird
claird at lairds.com
Mon Dec 22 19:50:40 EST 2003
In article <mailman.33.1072077235.684.python-list at python.org>,
Benjamin Han <bhan at andrew.cmu.edu> wrote:
>On Mon, 22 Dec 2003, Andrew Bennetts wrote:
>> On Mon, Dec 22, 2003 at 01:38:27AM -0500, Benjamin Han wrote:
>> > On Mon, 22 Dec 2003, Jp Calderone wrote:
>> [...]
>> > > import os, errno
>> > >
>> > > def shouldRun():
>> > > try:
>> > > os.mkdir(MAGIC_PATH)
>> > > except OSError, e:
>> > > if e.args[0] == errno.EEXIST:
>> > > return False
>> > > raise
>> > > return True
>> >
>> > But this solution creates a file race condition?
>>
>> How? mkdir is atomic. Either it creates the directory and succeeds, or it
>> fails. I don't see any problems here.
>
>ok I see. The reason I'm thinking of using a lock file through fcntl is that
>even if a lock file exists (maybe due to a crash of some sort before), using
>the locking mechanism would still work. The "test if it exists" approach
>would fail because of some leftover from some accidental 'death' of the process
>before.
>
>Any more suggestion? Thanks.
>
Open a socket service. I expected Andrew to write that.
Here's how I think about this: what does the OS itself manage
as a process-referring singleton? Socket service! Only one
server can be on a port at a time; that's exactly the expressed
requirement.
Apparently I haven't needed this yet in Python. If you're will-
ing to read along in a foreign language, though, <URL: http://
wiki.tcl.tk/singleton > comments on Tcl-based implementations.
--
Cameron Laird <claird at phaseit.net>
Business: http://www.Phaseit.net
More information about the Python-list
mailing list