Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fcntl problems
- From: semanticist at gmail.com (Miles)
- Subject: fcntl problems
- Date: Fri, 31 Aug 2007 10:42:49 -0400
On 8/31/07, mhearne808 wrote:
> I have a script that will be run from a cron job once a minute. One
> of the things this script will do is open a file to stash some
> temporary results. I expect that this script will always finish its
> work in less than 15 seconds, but I didn't want to depend on that.
> Thus I started to look into file locking, which I had hoped I could
> use in the following fashion:
>
> Process A opens file foo
> Process A locks file foo
> Process A takes more than a minute to do its work
> Process B wakes up
> Process B determines that file foo is locked
> Process B quits in disgust
> Process A finishes its work
That would look like (untested):
import fcntl, sys
f = open('foo', 'w+')
try:
fcntl.flock(f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError, e:
if e.args[0] == 35:
sys.exit(1)
else:
raise
f.seek(0, 2) # seek to end
# do your thing with the file
f.flush()
fcntl.flock(f.fileno(), fcntl.LOCK_UN)
f.close()
-Miles
- References:
- fcntl problems
- From: mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
- fcntl problems
- From: mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
- fcntl problems
- From: mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
- fcntl problems
- Prev by Date: Fatal Python error using ctypes & python exceptions
- Next by Date: Question involving a Python app...
- Previous by thread: fcntl problems
- Next by thread: fcntl problems
- Index(es):