summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/tasks.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-27 10:28:41 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-27 10:28:41 (GMT)
commitbbd96c6f47046e11f47de06550dcd1c816aad71c (patch)
treecfc97c37518b3e86bdf1e470ab8f7fea8dcf73f6 /Lib/asyncio/tasks.py
parentc4cca45baf89f694ac86ee950a742c0a56e8dc7f (diff)
downloadcpython-bbd96c6f47046e11f47de06550dcd1c816aad71c.zip
cpython-bbd96c6f47046e11f47de06550dcd1c816aad71c.tar.gz
cpython-bbd96c6f47046e11f47de06550dcd1c816aad71c.tar.bz2
asyncio, Tulip issue 137: In debug mode, add the traceback where the coroutine
object was created to the "coroutine ... was never yield from" log
Diffstat (limited to 'Lib/asyncio/tasks.py')
-rw-r--r--Lib/asyncio/tasks.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 52ca33a..89ec3a4 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -43,6 +43,7 @@ class CoroWrapper:
assert inspect.isgenerator(gen), gen
self.gen = gen
self.func = func
+ self._source_traceback = traceback.extract_stack(sys._getframe(1))
def __iter__(self):
return self
@@ -81,13 +82,13 @@ class CoroWrapper:
gen = getattr(self, 'gen', None)
frame = getattr(gen, 'gi_frame', None)
if frame is not None and frame.f_lasti == -1:
- func = self.func
- code = func.__code__
- filename = code.co_filename
- lineno = code.co_firstlineno
- logger.error(
- 'Coroutine %r defined at %s:%s was never yielded from',
- func.__name__, filename, lineno)
+ func = events._format_callback(self.func, ())
+ tb = ''.join(traceback.format_list(self._source_traceback))
+ message = ('Coroutine %s was never yielded from\n'
+ 'Coroutine object created at (most recent call last):\n'
+ '%s'
+ % (func, tb.rstrip()))
+ logger.error(message)
def coroutine(func):
@@ -112,6 +113,8 @@ def coroutine(func):
@functools.wraps(func)
def wrapper(*args, **kwds):
w = CoroWrapper(coro(*args, **kwds), func)
+ if w._source_traceback:
+ del w._source_traceback[-1]
w.__name__ = func.__name__
if _PY35:
w.__qualname__ = func.__qualname__