Super simple file based locking
Super simple file-based locking:
# first.py from ezlock import Lock import time with Lock(): print("I got the lock and I'm keeping it for 20s") time.sleep(20)
# second.py ... with Lock(): print("Trying to get a lock too")
>>> python3 first.py & I got the lock and I'm keeping it for 20s >>> echo "before 20s" before 20s >>> python3 second.py locking.LockError: Attempted to acquire on already locked lock!
Lock files have an owner. A lock can check if it owns a file with
Locks will only release a lock that's not theirs if it's forced i.e.
You can wait for a lock to be released with
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.