|
19 | 19 | import asyncio |
20 | 20 | import platform |
21 | 21 | import sys |
22 | | -import tracemalloc |
23 | 22 | import typing as t |
24 | 23 | from functools import wraps |
25 | 24 | from inspect import isclass |
@@ -91,8 +90,11 @@ def copy_signature(_: _FuncT) -> t.Callable[[t.Callable], _FuncT]: |
91 | 90 | return _id |
92 | 91 |
|
93 | 92 |
|
94 | | -def deprecation_warn(message, stack_level=1): |
95 | | - warn(message, category=DeprecationWarning, stacklevel=stack_level + 1) |
| 93 | + |
| 94 | +# Copy globals as function locals to make sure that they are available |
| 95 | +# during Python shutdown when the Pool is destroyed. |
| 96 | +def deprecation_warn(message, stack_level=1, _warn=warn): |
| 97 | + _warn(message, category=DeprecationWarning, stacklevel=stack_level + 1) |
96 | 98 |
|
97 | 99 |
|
98 | 100 | def deprecated(message: str) -> t.Callable[[_FuncT], _FuncT]: |
@@ -224,12 +226,9 @@ def inner(*args, **kwargs): |
224 | 226 | return decorator |
225 | 227 |
|
226 | 228 |
|
227 | | -def unclosed_resource_warn(obj): |
228 | | - msg = f"Unclosed {obj!r}." |
229 | | - trace = tracemalloc.get_object_traceback(obj) |
230 | | - if trace: |
231 | | - msg += "\nObject allocated at (most recent call last):\n" |
232 | | - msg += "\n".join(trace.format()) |
233 | | - else: |
234 | | - msg += "\nEnable tracemalloc to get the object allocation traceback." |
235 | | - warn(msg, ResourceWarning, stacklevel=2, source=obj) |
| 229 | +# Copy globals as function locals to make sure that they are available |
| 230 | +# during Python shutdown when the Pool is destroyed. |
| 231 | +def unclosed_resource_warn(obj, _warn=warn): |
| 232 | + cls_name = obj.__class__.__name__ |
| 233 | + msg = f"unclosed {cls_name}: {obj!r}." |
| 234 | + _warn(msg, ResourceWarning, stacklevel=2, source=obj) |
0 commit comments