summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-08-14 15:29:28 -0400
committerYury Selivanov <yselivanov@sprymix.com>2015-08-14 15:29:28 -0400
commit8d79c57726e30fd19d5fadf46375853df7895516 (patch)
tree000fe08ec71e68c127b7e0ca1dea5159028527e4
parentf3ed6c3e8a857d7e93ff7ae74f3f48d7b1252179 (diff)
downloadtrollius-git-master.tar.gz
Fix Task.get_stask() for 'async def' coroutineslistmaster
-rw-r--r--asyncio/tasks.py6
-rw-r--r--tests/test_tasks.py32
2 files changed, 37 insertions, 1 deletions
diff --git a/asyncio/tasks.py b/asyncio/tasks.py
index 9bfc1cf..a235e74 100644
--- a/asyncio/tasks.py
+++ b/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/tests/test_tasks.py b/tests/test_tasks.py
index 251192a..0426787 100644
--- a/tests/test_tasks.py
+++ b/tests/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)