diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-08-14 19:30:59 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-08-14 19:30:59 (GMT) |
commit | 233983380d1868126918fd86252d6328b0f0ad50 (patch) | |
tree | 50f48cac80e83f35ab89016b64e32b2ef7687eb6 | |
parent | ac37ba0742b1eb794eca7b6fd95a1ffecc9b6333 (diff) | |
download | cpython-233983380d1868126918fd86252d6328b0f0ad50.zip cpython-233983380d1868126918fd86252d6328b0f0ad50.tar.gz cpython-233983380d1868126918fd86252d6328b0f0ad50.tar.bz2 |
Issue #24867: Fix Task.get_stack() for 'async def' coroutines
-rw-r--r-- | Lib/asyncio/tasks.py | 6 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_tasks.py | 32 |
2 files changed, 37 insertions, 1 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 9bfc1cf..a235e74 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -128,7 +128,11 @@ class Task(futures.Future): returned for a suspended coroutine. """ frames = [] - f = self._coro.gi_frame + try: + # 'async def' coroutines + f = self._coro.cr_frame + except AttributeError: + f = self._coro.gi_frame if f is not None: while f is not None: if limit is not None: diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 251192a..0426787 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2,6 +2,7 @@ import contextlib import functools +import io import os import re import sys @@ -162,6 +163,37 @@ class TaskTests(test_utils.TestCase): 'function is deprecated, use ensure_'): self.assertIs(f, asyncio.async(f)) + def test_get_stack(self): + T = None + + @asyncio.coroutine + def foo(): + yield from bar() + + @asyncio.coroutine + def bar(): + # test get_stack() + f = T.get_stack(limit=1) + try: + self.assertEqual(f[0].f_code.co_name, 'foo') + finally: + f = None + + # test print_stack() + file = io.StringIO() + T.print_stack(limit=1, file=file) + file.seek(0) + tb = file.read() + self.assertRegex(tb, r'foo\(\) running') + + @asyncio.coroutine + def runner(): + nonlocal T + T = asyncio.ensure_future(foo(), loop=self.loop) + yield from T + + self.loop.run_until_complete(runner()) + def test_task_repr(self): self.loop.set_debug(False) |