On 2017-04-20, Cameron Simpson <c...@zip.com.au> wrote:
> Others have pointed the way to an exact implementation.
>
> For myself, I like mkdir. It is portable. It is atomic. It fails if
> the target exists.  It works over NFS etc. It is easy.
>
>   os.mkdir('lock')
>   ... do stuff ...
>   os.rmdir('lock')

One downside to this is that if the process that 'holds the lock'
dies before it reaches the 'rmdir' then the lock becomes wedged.
With the 'flock' method, the operating system will automatically
undo the lock. Of course, depending on your application, it's possible
that this 'downside' may be a feature.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to