changeset: 97384:c0b7829e3074 parent: 97381:b0a6bba16b9c parent: 97383:d25022765186 user: Yury Selivanov date: Fri Aug 14 15:35:14 2015 -0400 files: Misc/NEWS description: Merge 3.5 (issue #24867) diff -r b0a6bba16b9c -r c0b7829e3074 Lib/asyncio/tasks.py --- a/Lib/asyncio/tasks.py Fri Aug 14 11:09:56 2015 -0700 +++ b/Lib/asyncio/tasks.py Fri Aug 14 15:35:14 2015 -0400 @@ -128,7 +128,11 @@ 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 -r b0a6bba16b9c -r c0b7829e3074 Lib/test/test_asyncio/test_pep492.py --- a/Lib/test/test_asyncio/test_pep492.py Fri Aug 14 11:09:56 2015 -0700 +++ b/Lib/test/test_asyncio/test_pep492.py Fri Aug 14 15:35:14 2015 -0400 @@ -186,6 +186,23 @@ data = self.loop.run_until_complete(coro()) self.assertEqual(data, 'spam') + def test_task_print_stack(self): + T = None + + async def foo(): + f = T.get_stack(limit=1) + try: + self.assertEqual(f[0].f_code.co_name, 'foo') + finally: + f = None + + async def runner(): + nonlocal T + T = asyncio.ensure_future(foo(), loop=self.loop) + await T + + self.loop.run_until_complete(runner()) + if __name__ == '__main__': unittest.main() diff -r b0a6bba16b9c -r c0b7829e3074 Lib/test/test_asyncio/test_tasks.py --- a/Lib/test/test_asyncio/test_tasks.py Fri Aug 14 11:09:56 2015 -0700 +++ b/Lib/test/test_asyncio/test_tasks.py Fri Aug 14 15:35:14 2015 -0400 @@ -2,6 +2,7 @@ import contextlib import functools +import io import os import re import sys @@ -162,6 +163,37 @@ '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) diff -r b0a6bba16b9c -r c0b7829e3074 Misc/NEWS --- a/Misc/NEWS Fri Aug 14 11:09:56 2015 -0700 +++ b/Misc/NEWS Fri Aug 14 15:35:14 2015 -0400 @@ -87,6 +87,8 @@ - Issue #13248: Remove deprecated inspect.getargspec and inspect.getmoduleinfo functions. +- Issue #24867: Fix Task.get_stack() for 'async def' coroutines + Documentation -------------