flock inspired by https://github.com/tox-dev/filelock from flock import Flock with Flock("test.lock"): ...