summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/tasks.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-12 16:39:26 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-12 16:39:26 (GMT)
commit307bccc6ff6670c58f4c20421a29071ff710e6a3 (patch)
treee165b2e33505bcece03948112ca230af5d2d2688 /Lib/asyncio/tasks.py
parentf54432e2a16d445ed6fa142a9c5d8d23b11780b2 (diff)
downloadcpython-307bccc6ff6670c58f4c20421a29071ff710e6a3.zip
cpython-307bccc6ff6670c58f4c20421a29071ff710e6a3.tar.gz
cpython-307bccc6ff6670c58f4c20421a29071ff710e6a3.tar.bz2
asyncio: Tulip issue 173: Enhance repr(Handle) and repr(Task)
repr(Handle) is shorter for function: "foo" instead of "<function foo at 0x...>". It now also includes the source of the callback, filename and line number where it was defined, if available. repr(Task) now also includes the current position in the code, filename and line number, if available. If the coroutine (generator) is done, the line number is omitted and "done" is added.
Diffstat (limited to 'Lib/asyncio/tasks.py')
-rw-r--r--Lib/asyncio/tasks.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 8b8fb82..e6fd3d3 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -188,7 +188,15 @@ class Task(futures.Future):
i = res.find('<')
if i < 0:
i = len(res)
- res = res[:i] + '(<{}>)'.format(self._coro.__name__) + res[i:]
+ text = self._coro.__name__
+ coro = self._coro
+ if inspect.isgenerator(coro):
+ filename = coro.gi_code.co_filename
+ if coro.gi_frame is not None:
+ text += ' at %s:%s' % (filename, coro.gi_frame.f_lineno)
+ else:
+ text += ' done at %s' % filename
+ res = res[:i] + '(<{}>)'.format(text) + res[i:]
return res
def get_stack(self, *, limit=None):