Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57085

Re: Inter-process locking

References <mailman.1025.1381541497.18130.python-list@python.org> <m2vc13rup4.fsf@cochabamba.vanoostrum.org> <mailman.1048.1381639375.18130.python-list@python.org> <m261t1qqx9.fsf@cochabamba.vanoostrum.org>
Date 2013-10-18 20:08 -0600
Subject Re: Inter-process locking
From Jason Friedman <jsf80238@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1249.1382148520.18130.python-list@python.org> (permalink)

Show all headers | View raw


> There is one caveat, however. If a process that has the lock crashes without releasing the lock, the lock file will stay around and prevent other processes to acquire it. Then you will have to manually remove it. I generally prefer a solution where the pid of the locking process is written to the lock file, so that other processes trying to acquire the lock can find out if the process is still around and remove the lock file if not. I have seen such solutions on Unix systems. But I am not sure if this can be done in a platform independent way without the risk of race conditions. Maybe I have to find out.

True, luckily my application need not be that accurate.  Competition
for the lock will be rare.  My present solution waits a few minutes
for the lock to become available, and if not available after that time
takes it forcefully (which lockfile handily provides).  Certainly not
foolproof, but we can recover merely by re-running, so if I get an
error or two each year that is acceptable.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Inter-process locking Jason Friedman <jsf80238@gmail.com> - 2013-10-11 17:44 -0600
  Re: Inter-process locking Piet van Oostrum <piet@vanoostrum.org> - 2013-10-12 00:15 -0400
    Re: Inter-process locking Jason Friedman <jsf80238@gmail.com> - 2013-10-12 22:42 -0600
      Re: Inter-process locking Piet van Oostrum <piet@vanoostrum.org> - 2013-10-13 08:46 -0400
        Re: Inter-process locking Jason Friedman <jsf80238@gmail.com> - 2013-10-18 20:08 -0600

csiph-web