Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
In two different PRs (gh-113754 andgh-11166) (both making separate, innocent-seeming changes to async generators), some test (but not the same one) is consistently reporting an attribute ontracemalloc.is_tracing(). Here's one.
test_async_gen_ags_gen_agt_gen (test.test_asyncgen.AsyncGenTest.test_async_gen_ags_gen_agt_gen) ... Warning -- Unraisable exceptionException ignored in: <async_generator object AsyncGenAsyncioTest.test_asyncgen_nonstarted_hooks_are_cancellable.<locals>.async_iterate at 0x7fe32080c050>Traceback (most recent call last): File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/warnings.py", line 112, in _showwarnmsg _showwarnmsg_impl(msg) File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/warnings.py", line 28, in _showwarnmsg_impl text = _formatwarnmsg(msg) File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/warnings.py", line 128, in _formatwarnmsg return _formatwarnmsg_impl(msg) File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/warnings.py", line 64, in _formatwarnmsg_impl tracing = tracemalloc.is_tracing()AttributeError: partially initialized module 'tracemalloc' from '/home/runner/work/cpython/cpython-ro-srcdir/Lib/tracemalloc.py' has no attribute 'is_tracing' (most likely due to a circular import)/home/runner/work/cpython/cpython-ro-srcdir/Lib/unittest/case.py:589: RuntimeWarning: coroutine method 'athrow' of 'AsyncGenTest.test_async_gen_ags_gen_agt_gen.<locals>.agen' was never awaited if method() is not None:RuntimeWarning: Enable tracemalloc to get the object allocation tracebackokI think theAttributeError maybe new? I've not seen it reported before. If there's no obvious root cause (other than that module finalization order is undefined), there's a simple fix: in warnings.py, where it says
try:importtracemalloc# Logging a warning should not raise a new exception:# catch Exception, not only ImportError and RecursionError.exceptException:# don't suggest to enable tracemalloc if it's not availabletracing=Truetb=Noneelse:
(and in theelse block callstracemalloc.is_tracing() andtracemalloc.get_object_traceback()), we could just add attribute accesses of those two functions to thetry block, so if the module is incomplete, we don't crash on those calls.