On Thu, Feb 17, 2005 at 12:42:55AM -0800, Michele Simionato wrote: > John Lenton: > > the operating system cleans up the lock. > > So, are you effectively saying than a custom made solution based on > flock can be quite reliable and it could be a reasonable choice to > use shelve+flock for small/hobbysts sites? I always thought locking > was a bad beast and feared to implement it myself, but maybe I was > wrong afterall ...
locking works very well, when it works. If you're on Linux, the manpage for flock has a NOTES section you should read. I don't know how direct the mapping between python's flock/lockf and the OSs flock/lockf are, you might want to look into that as well (but you'd only really care if you are in one of the corner cases mentioned in the referred NOTES section). In some weird corner cases you'd have to revert to some other locking scheme, but the same pattern applies, however: subclass whatever it is you want to use, wrapping the appropriate methods in try/finally lock/unlocks; you just want to change the flock to some other thing. Also, if you use something where the process doesn't terminate between calls (such as mod_python, I guess), you have to be sure to write the try/finallys around your locking code, because the OS only cleans up the lock when the process exits. -- John Lenton ([EMAIL PROTECTED]) -- Random fortune: Keep emotionally active. Cater to your favorite neurosis.
signature.asc
Description: Digital signature
-- http://mail.python.org/mailman/listinfo/python-list