When using portalocker, keep these technical details in mind:
Unix/Linux
Unix file locks are advisory. All participating processes must explicitly acquire the lock to respect it.
Network Filesystems (NFS/etc.)
Network filesystems have unique locking and buffering behaviors. To ensure data integrity before releasing a lock, you may need to manually flush and sync the file handle:
fh.flush()
os.fsync(fh.fileno())
PidFileLock Behavior
By default, a PidFileLock context is for inspection. The body of the context runs even if another process holds the lock; it returns the holder's PID (or None if the current process acquired it). To ensure the body only runs after successful acquisition, use .fail_closed().
RedisLock Behavior
RedisLock uses a pub/sub subscription. Ownership is released when the subscription is removed. If a network partition occurs, the holder may observe a loss of the lock. For advanced usage, see documentation regarding lost, ensure_held(), health checks, and fencing tokens.