Skip to content

Instantly share code, notes, and snippets.

@jeremyephron
jeremyephron / script_lock.py
Last active January 11, 2024 14:02
A script lock in Python to prevent the same script from being run more than once at a time
import errno
import fcntl
from pathlib import Path
def lock_script() -> bool:
"""
Locks a file pertaining to this script so that it cannot be run simultaneously.
Since the lock is automatically released when this script ends, there is no
need for an unlock function for this use case.