Determine what the calling program is

Peter J. Holzer hjp-python at hjp.at
Mon Apr 19 17:13:41 EDT 2021


On 2021-04-19 08:54:06 +1000, Cameron Simpson wrote:
> My personal preference is lock directories. Shell version goes like 
> this:
> 
>     if mkdir /my/lock/directory/name-of-task
>     then
>        .. do task ..
>        rmdir /my/lock/directory/name-of-task
>     else
>       echo "lock /my/lock/directory/name-of-task already taken"
>     fi
> 
> Simple, reliable, even works over NFS if you care.

Reliable only if "fail locked" is acceptable. If that process dies for
some reason the lock directory will stay behind, blocking other
processes until somebody notices the problem and removes it.

The fcntl method suggested by several people has the advantage that the
lock vanished with the process which holds it.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20210419/a8f4bf47/attachment.sig>


More information about the Python-list mailing list