File tree 2 files changed +6
-3
lines changed
2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -58,15 +58,16 @@ def _formatwarnmsg_impl(msg):
58
58
# catch Exception, not only ImportError and RecursionError.
59
59
except Exception :
60
60
# don't suggest to enable tracemalloc if it's not available
61
- tracing = True
61
+ suggest_tracemalloc = False
62
62
tb = None
63
63
else :
64
- tracing = tracemalloc .is_tracing ()
65
64
try :
65
+ suggest_tracemalloc = not tracemalloc .is_tracing ()
66
66
tb = tracemalloc .get_object_traceback (msg .source )
67
67
except Exception :
68
68
# When a warning is logged during Python shutdown, tracemalloc
69
69
# and the import machinery don't work anymore
70
+ suggest_tracemalloc = False
70
71
tb = None
71
72
72
73
if tb is not None :
@@ -85,7 +86,7 @@ def _formatwarnmsg_impl(msg):
85
86
if line :
86
87
line = line .strip ()
87
88
s += ' %s\n ' % line
88
- elif not tracing :
89
+ elif suggest_tracemalloc :
89
90
s += (f'{ category } : Enable tracemalloc to get the object '
90
91
f'allocation traceback\n ' )
91
92
return s
Original file line number Diff line number Diff line change
1
+ Silence unraisable AttributeError when warnings are emitted during Python
2
+ finalization.
You can’t perform that action at this time.
0 commit comments