[Tutor] Lock File Usage

Ben Finney ben+python at benfinney.id.au
Mon Jan 30 19:33:10 EST 2017


"ad^2" <adsquaired at gmail.com> writes:

>  So, IF: no lock file, create a lock file, execute, delete lock file
> when finished successfully. ElSE: the script is running, exit. Then,
> cron will try again an hour later.
>
> I do not necessarily require a "lock file" just looking for a
> recommendation on a best practice with low complexity to make this
> work.

The third-party ‘fasteners’ library provides an API for locks
<URL:https://pypi.python.org/pypi/fasteners> that you will want to
consider.

Specifically, the interpprocess lock decorators
<URL:https://fasteners.readthedocs.io/en/latest/examples.html#lock-decorator>
seem to be what you want.

-- 
 \            “… Nature … is seen to do all things Herself and through |
  `\         herself of own accord, rid of all gods.” —Titus Lucretius |
_o__)                                                 Carus, c. 40 BCE |
Ben Finney



More information about the Tutor mailing list