|
7 | 7 |
|
8 | 8 | _CMD_USAGE = "python -m memory_profiler script_file.py" |
9 | 9 |
|
10 | | -from asyncio import iscoroutinefunction |
11 | 10 | from contextlib import contextmanager |
12 | 11 | from functools import partial, wraps |
13 | | -from types import coroutine |
| 12 | +from inspect import iscoroutinefunction |
14 | 13 | import builtins |
15 | 14 | import inspect |
16 | 15 | import linecache |
@@ -756,11 +755,12 @@ def wrap_function(self, func): |
756 | 755 | """ |
757 | 756 |
|
758 | 757 | if iscoroutinefunction(func): |
759 | | - @coroutine |
760 | | - def f(*args, **kwargs): |
| 758 | + # Use native `async def` / `await` rather than the legacy |
| 759 | + # `@types.coroutine` generator wrapper, which is rejected by |
| 760 | + # `asyncio.create_task()` in Python 3.12+. |
| 761 | + async def f(*args, **kwargs): |
761 | 762 | with self._count_ctxmgr(): |
762 | | - res = yield from func(*args, **kwargs) |
763 | | - return res |
| 763 | + return await func(*args, **kwargs) |
764 | 764 | else: |
765 | 765 | def f(*args, **kwds): |
766 | 766 | with self._count_ctxmgr(): |
@@ -1156,10 +1156,9 @@ def profile(func=None, stream=None, precision=1, backend='psutil'): |
1156 | 1156 | ) |
1157 | 1157 | if iscoroutinefunction(func): |
1158 | 1158 | @wraps(wrapped=func) |
1159 | | - @coroutine |
1160 | | - def wrapper(*args, **kwargs): |
| 1159 | + async def wrapper(*args, **kwargs): |
1161 | 1160 | prof = get_prof() |
1162 | | - val = yield from prof(func)(*args, **kwargs) |
| 1161 | + val = await prof(func)(*args, **kwargs) |
1163 | 1162 | show_results_bound(prof) |
1164 | 1163 | return val |
1165 | 1164 | else: |
|
0 commit comments