Skip to content

fix: lock that does not lock, and undeclared typing_extensions - #15

Merged
tlambert03 merged 2 commits into
funkelab:mainfrom
tlambert03:fix-lock-and-typing-extensions
Sep 30, 2026
Merged

tlambert03 merged 2 commits into
funkelab:mainfrom
tlambert03:fix-lock-and-typing-extensions

Conversation

@tlambert03

Copy link
Copy Markdown
Member

Two problems found while working on funkey/waterz#25.

The lock did not lock anything

The lock file was created in the temporary directory that holds the source, which is a different one for every call. No two processes ever locked the same file, so processes compiling the same module for the first time all compiled it, into the same destination.

With four processes doing that (the new test_concurrent_compilation), on main:

ld: open() failed, errno=17 (File exists) for '.../_witty_module_4a6f29fae0e2e2174acec66e8dc17f6f.cpython-314-darwin.so'
clang: error: linker command failed with exit code 1

Now:

  • the lock file is next to the module (<module>.lock in the output directory), so that one process compiles and the others wait and load the result
  • the module is built in a temporary directory next to its destination and moved there with os.replace, so that it is never there in parts (for example if the build is interrupted)

On Windows, the lock was on os.path.getsize(lock_file) bytes, which is 0 for a file that was just opened for writing. It is one byte now, and it retries, since LK_LOCK gives up after ten seconds, which is less than a compilation can take. I could not run this on Windows locally; the new test runs there in CI.

Not addressed: nb_combined.o for nanobind modules is built into the cache directory under the lock of the module that needs it, so two different nanobind modules compiled concurrently for the first time can still both build it.

typing_extensions is imported, and not a dependency

$ uv venv --python 3.14 && uv pip install witty && python -c "import witty"
ModuleNotFoundError: No module named 'typing_extensions'

It is only needed for deprecated, which is warnings.deprecated as of python 3.13. It is a dependency for older versions now, and not imported on newer ones.

Testing

  • test_concurrent_compilation fails on main and passes here (macOS, python 3.9, 3.12, 3.13, 3.14)
  • clean environments with nothing but witty: python 3.12 (installs typing_extensions) and 3.14 (does not)

🤖 Generated with Claude Code

tlambert03 and others added 2 commits September 29, 2026 16:35
`import witty` failed in an environment that does not happen to have
typing_extensions (it is imported for `deprecated`, which is in `warnings`
as of python 3.13).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The lock file was in a temporary directory, which is a different one for each
process: nothing was locked. Two processes compiling the same module for the
first time would both write it, and fail (or load a module that is there in
parts).

The lock file is now next to the module, and the module is built next to its
destination, to then be moved there at once.

On Windows, the lock was on as many bytes as there are in the lock file, which
is none.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.69%. Comparing base (d30f274) to head (bf769f0).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/witty/compile_module.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #15      +/-   ##
==========================================
- Coverage   92.94%   92.69%   -0.25%     
==========================================
  Files           2        2              
  Lines         170      178       +8     
==========================================
+ Hits          158      165       +7     
- Misses         12       13       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tlambert03
tlambert03 merged commit 3a9209f into funkelab:main Sep 30, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants