Skip to content

Conversation

gracetyy
Copy link
Contributor

Fixes #2969.

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation (not required for this bugfix)

Problem

Race condition in _virtualenv.py causes NameError: name '_DISTUTILS_PATCH' is not defined when the file is being overwritten (e.g., by uv venv --allow-existing) while another process is using it (e.g., marimo notebook).

Solution

Added defensive try-except NameError blocks around _DISTUTILS_PATCH and patch_dist references in _Finder.find_spec(), _Finder.exec_module(), and _Finder.load_module() methods to handle the race condition.

@gracetyy gracetyy force-pushed the fix/distutils_patch branch from 8f657b6 to 629f7b8 Compare October 12, 2025 17:43
@gracetyy gracetyy requested a review from gaborbernat October 12, 2025 19:10
@gracetyy
Copy link
Contributor Author

Sorry for all the issues in the previous commit! I've addressed all your feedback and thank you for your time.

@gracetyy gracetyy requested a review from gaborbernat October 16, 2025 14:53
@gaborbernat gaborbernat enabled auto-merge October 16, 2025 22:43
@gaborbernat gaborbernat merged commit 0a644b0 into pypa:main Oct 16, 2025
51 checks passed
@gracetyy
Copy link
Contributor Author

Thanks

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.

NameError: name '_DISTUTILS_PATCH' is not defined

2 participants