Replaces fcntl with filelock to avoid windows import issues#5544
Conversation
The from_files spawner imported `fcntl` unconditionally at module load to serialize USD downloads across distributed ranks. `fcntl` is Unix-only, so importing the spawner on Windows raised `ModuleNotFoundError: No module named 'fcntl'` even for single-rank runs that never take the lock path. Switch to `filelock.FileLock`, which selects `fcntl` on POSIX and `msvcrt` on Windows, and use `contextlib.nullcontext` for the single-rank case so the lock is allocated only when needed. Declare `filelock` in `install_requires` — it was previously available only as a transitive of `transformers`/`huggingface_hub`.
Greptile SummaryThis PR fixes a Windows import failure in
Confidence Score: 5/5The change is a minimal, well-scoped replacement of a Unix-only primitive with an equivalent cross-platform one; no behavioral differences are introduced on existing POSIX systems. Both the locking path ( No files require special attention; all three changed files are straightforward. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[_spawn_from_usd_file called] --> B{LOCAL_WORLD_SIZE > 1?}
B -- Yes --> C[lock = FileLock\nisaaclab_usd_spawn.lock]
B -- No --> D[lock = nullcontext]
C --> E[with lock: acquire exclusive file lock]
D --> E
E --> F{file_status == 2?}
F -- Yes --> G[retrieve_file_path\nforce_download=False]
F -- No --> H[get_current_stage]
G --> H
H --> I{prim exists at prim_path?}
I -- No --> J[create_prim]
I -- Yes --> K[log warning]
J --> L[release lock / exit context]
K --> L
L --> M[modify variants, rigid body,\ncollision, mass props...]
Reviews (1): Last reviewed commit: "Fix from_files spawner import on Windows" | Re-trigger Greptile |
The docs CI installs only `docs/requirements.txt`, which omits `filelock`. Sphinx autodoc therefore fails to import the `from_files` module (which now uses `filelock.FileLock`), producing three "failed to import" warnings that are treated as errors. Add `filelock` to `autodoc_mock_imports` alongside the other small utility libraries already mocked there.
Description
The
isaaclab.sim.spawners.from_filesmodule importsfcntlunconditionally at module load.fcntlis Unix-only, so on Windows the import fails with:This breaks any Windows usage of the spawner — including single-GPU runs that never take the lock path. Reproducer reported by a user (IsaacLab
develop@b258e87, IsaacSim6.0.0rc41):fcntlwas introduced in #5032 to serialize USD download/stage composition across distributed ranks (preventing segfaults inSdf_CrateFile::_MmapStream::Readon shared cached USD files). The intent is correct — only the implementation is Unix-only.Change
fcntl.flockwithfilelock.FileLock, which usesfcntlon POSIX andmsvcrton Windows.contextlib.nullcontextfor the single-rank path so the lock file is only created when actually needed (i.e.,LOCAL_WORLD_SIZE > 1).try/finallyand the# noqa: SIM115on the bareopen(...)— thewith FileLock(...)form is exception-safe.filelockinsource/isaaclab/setup.py::INSTALL_REQUIRES. It was previously only transitively available viatransformers→huggingface_hub; making it a direct dep so we don't depend on a transitive chain that could change.The lock semantics are unchanged: an exclusive advisory lock on
<tempdir>/isaaclab_usd_spawn.lock, held only whileLOCAL_WORLD_SIZE > 1.Original lock implementation: @ooctipus (#5032) — tagging for review since this changes the locking primitive.
Type of change
Screenshots
N/A — import-time failure on Windows; no UI surface.
Checklist
pre-commitchecks with./isaaclab.sh --formatimport fcntlat module load on Windows; a regression test would require a Windows CI runner, which IsaacLab does not currently exercise. Locally verified the module imports andFileLockresolves tofilelock._unix.UnixFileLockon Linux (and would resolve toWindowsFileLockon Windows).source/<pkg>/changelog.d/for every touched package (do not editCHANGELOG.rstor bumpextension.toml— CI handles that)CONTRIBUTORS.mdor my name already exists there