Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AttributeError fortracemalloc.is_tracing #113781

Closed
Labels
testsTests in the Lib/test dir
@gvanrossum

Description

@gvanrossum

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 tracebackok

I 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.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp