diff --git a/cron/scheduler.py b/cron/scheduler.py index 23cf5cd61..8800b2fca 100644 --- a/cron/scheduler.py +++ b/cron/scheduler.py @@ -280,6 +280,7 @@ def tick(verbose: bool = True) -> int: _LOCK_DIR.mkdir(parents=True, exist_ok=True) # Cross-platform file locking: fcntl on Unix, msvcrt on Windows + lock_fd = None try: lock_fd = open(_LOCK_FILE, "w") if fcntl: @@ -288,6 +289,8 @@ def tick(verbose: bool = True) -> int: msvcrt.locking(lock_fd.fileno(), msvcrt.LK_NBLCK, 1) except (OSError, IOError): logger.debug("Tick skipped — another instance holds the lock") + if lock_fd is not None: + lock_fd.close() return 0 try: