-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[BUG]: retranslating local exception with custom data class hangs in free-threading cpython #5346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think the easiest approach might be to use a different mutex for the exception translators than for the rest of the internals. Other than initialization and finalization, I think the accesses for exception translators and the rest of internals are separate The alternative is to unlock before calling exception translators, but to do that safely I think you may need to copy the list of translators. |
Thanks @colesbury let me check these approaches! I tried another alternative doing the following, checking whether the mutex is already locked and lock it only if unlocked:
What do you think? |
That looks like it would skip locking the mutex if it's held by another thread, which would not be safe. But also, your sample code only locks the mutex if it's already locked, so I don't think it will ever get locked. |
…eptions (#5362) * Added exception translator specific mutex used with try_translate_exceptions Fixes #5346 * - Replaced with_internals_for_exception_translator by with_exception_translators - Incremented PYBIND11_INTERNALS_VERSION - Added a test * style: pre-commit fixes * Fixed formatting and added explicit to ctors * Addressed PR review comments --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Required prerequisites
What version (or hash if on master) of pybind11 are you using?
2.13.5 and from source
Problem description
I have a program stuck when retranslating local exception with custom data class using CPython with free-threading mode enabled.
This is due to
internals.mutex
being in the locked state when the callback is running. When using custom data,all_type_info_get_cache
method is called internally which also tries to lockinternals.mutex
.See the repro code below
Reproducible example code
C++ test1.cpp
Python code:
exceptions1.py
Run:
python -c "import test1; test1.check()"
Output:
Is this a regression? Put the last known working version here if it is.
Not a regression
The text was updated successfully, but these errors were encountered: