-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Switch to a new thread-safe utility for catching warnings. #25626
Conversation
There are some test failures because there are still some uses of |
FYI: python/cpython#128300 : Add thread-safe context manager to "warnings" module This is going to take some time to get fixed in CPython but it might be a good idea to make a similar API so that you can switch back to the CPython version in the future, assuming it gets fixed properly. If you have any feedback on my PR, I would be happy to hear about it. My main concerns were to not break existing non-threaded non-async code that is happily using |
8d0bad1
to
2351fbb
Compare
Thanks! I'm excited to see that this is being fixed properly upstream. Given I just added a fallback path for non-threaded cases that calls the upstream utilities, it shouldn't be a big lift to switch back to the upstream utilities for the threaded cases also when a thread-safe alternative exists. I'd assume that your improved warnings will not land until Python 3.14, correct? |
253a908
to
be66011
Compare
The Python warnings.catch_warnings() functionality is not thread-safe (https://py-free-threading.github.io/porting/#the-warnings-module-is-not-thread-safe), so we cannot use it during tests that use free-threading. This change introduces a private warnings test helper (test_warning_util.py), which hooks the CPython warning infrastructure and uses it to implement thread-safe warnings infrastructure. This requires a handful of small modifications to tests to remove direct uses of the warnings module. We also sadly have to delete one TPU test that checks for a warning raised on another thread; there's no easy way for us to catch that in a thread-safe way, but that test seems like overkill anyway.
The Python warnings.catch_warnings() functionality is not thread-safe (https://py-free-threading.github.io/porting/#the-warnings-module-is-not-thread-safe), so we cannot use it during tests that use free-threading. This change introduces a private warnings test helper (test_warning_util.py), which hooks the CPython warning infrastructure and uses it to implement thread-safe warnings infrastructure.
This requires a handful of small modifications to tests to remove direct uses of the warnings module. We also sadly have to delete one TPU test that checks for a warning raised on another thread; there's no easy way for us to catch that in a thread-safe way, but that test seems like overkill anyway.