fix: allow background worker to start on Windows (fcntl ImportError, #89) - #261
Open
haidrrrry wants to merge 1 commit into
Open
fix: allow background worker to start on Windows (fcntl ImportError, #89)#261haidrrrry wants to merge 1 commit into
haidrrrry wants to merge 1 commit into
Conversation
worker.py imported `fcntl` at module top level. fcntl is a Unix-only module, so on Windows the import raised ImportError and the standalone background worker could not start at all (issue HKUDS#89). Make the POSIX file-locking backend optional and fall back to msvcrt on Windows for the single-instance lock: - import fcntl guarded by try/except; fall back to msvcrt, else None - _acquire_file_lock uses fcntl.flock, else msvcrt.locking(LK_NBLCK), else logs a warning and continues without singleton enforcement - _release_file_lock mirrors the same backends - broadened the contention except to (BlockingIOError, OSError) since msvcrt raises OSError when the region is already locked The other Windows-hostile calls in this file (os.nice, add_signal_handler) are already wrapped in try/except and degrade cleanly, so no change needed. Closes HKUDS#89
haidrrrry
force-pushed
the
fix/worker-fcntl-windows
branch
from
July 1, 2026 07:21
cee67e1 to
af52aae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (issue #89)
service/server/worker.pyimportsfcntlat module top level:fcntlis a Unix-only standard-library module. On Windows the import raisesImportErrorimmediately, so the standalone background worker (python worker.py) cannot start at all. This matches the Windowsfcntlfailure reported in #89.Fix
Make the POSIX file-locking backend optional and fall back to
msvcrton Windows for the single-instance lock:import fcntlguarded bytry/except; on failure fall back tomsvcrt, elseNone_acquire_file_lockusesfcntl.flock, elsemsvcrt.locking(LK_NBLCK), else logs a warning and continues without singleton enforcement_release_file_lockmirrors the same backendsexceptbroadened to(BlockingIOError, OSError)becausemsvcrt.lockingraisesOSErrorwhen the region is already lockedThe other Windows-hostile calls in this file (
os.nice,loop.add_signal_handler) are already wrapped intry/exceptand degrade cleanly, so no change is needed there.Verification
Reproduced and verified with the
fcntlimport blocked to simulate Windows:fcntl)msvcrtpresent)msvcrt, second blocked, unlock on releaseOn the unmodified file the same simulation fails with
ImportError: No module named fcntl, confirming the fix.Closes #89