diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-10 22:21:27 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-10 22:21:27 (GMT) |
commit | c39ba7d611fe556314acc8c11cd9f805512db663 (patch) | |
tree | 21dc6e07bea4dae7705aa9ccd26326d05303f6aa /Lib/asyncio | |
parent | f68bd88aa61ae6214d3dc5552a7e3f9cf1401507 (diff) | |
download | cpython-c39ba7d611fe556314acc8c11cd9f805512db663.zip cpython-c39ba7d611fe556314acc8c11cd9f805512db663.tar.gz cpython-c39ba7d611fe556314acc8c11cd9f805512db663.tar.bz2 |
asyncio: sync with Tulip
- repr(Task) and repr(CoroWrapper) now also includes where these objects were
created. If the coroutine is not a generator (don't use "yield from"), use
the location of the function, not the location of the coro() wrapper.
- Fix create_task(): truncate the traceback to hide the call to create_task().
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/base_events.py | 5 | ||||
-rw-r--r-- | Lib/asyncio/coroutines.py | 24 | ||||
-rw-r--r-- | Lib/asyncio/tasks.py | 7 |
3 files changed, 28 insertions, 8 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 833f81d..f6d7a58 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -155,7 +155,10 @@ class BaseEventLoop(events.AbstractEventLoop): """Schedule a coroutine object. Return a task object.""" - return tasks.Task(coro, loop=self) + task = tasks.Task(coro, loop=self) + if task._source_traceback: + del task._source_traceback[-1] + return task def _make_socket_transport(self, sock, protocol, waiter=None, *, extra=None, server=None): diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py index 48730c2..4cbfa85 100644 --- a/Lib/asyncio/coroutines.py +++ b/Lib/asyncio/coroutines.py @@ -57,7 +57,7 @@ del has_yield_from_bug class CoroWrapper: - # Wrapper for coroutine in _DEBUG mode. + # Wrapper for coroutine object in _DEBUG mode. def __init__(self, gen, func): assert inspect.isgenerator(gen), gen @@ -68,8 +68,11 @@ class CoroWrapper: # decorator def __repr__(self): - return ('<%s %s>' - % (self.__class__.__name__, _format_coroutine(self))) + coro_repr = _format_coroutine(self) + if self._source_traceback: + frame = self._source_traceback[-1] + coro_repr += ', created at %s:%s' % (frame[0], frame[1]) + return '<%s %s>' % (self.__class__.__name__, coro_repr) def __iter__(self): return self @@ -181,9 +184,18 @@ def _format_coroutine(coro): coro_name = coro.__name__ filename = coro.gi_code.co_filename - if coro.gi_frame is not None: + if (isinstance(coro, CoroWrapper) + and not inspect.isgeneratorfunction(coro.func)): + filename, lineno = events._get_function_source(coro.func) + if coro.gi_frame is None: + coro_repr = '%s() done, defined at %s:%s' % (coro_name, filename, lineno) + else: + coro_repr = '%s() running, defined at %s:%s' % (coro_name, filename, lineno) + elif coro.gi_frame is not None: lineno = coro.gi_frame.f_lineno - return '%s() at %s:%s' % (coro_name, filename, lineno) + coro_repr = '%s() running at %s:%s' % (coro_name, filename, lineno) else: lineno = coro.gi_code.co_firstlineno - return '%s() done at %s:%s' % (coro_name, filename, lineno) + coro_repr = '%s() done, defined at %s:%s' % (coro_name, filename, lineno) + + return coro_repr diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index befc296..61f4822 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -101,7 +101,12 @@ class Task(futures.Future): else: info.append(self._state.lower()) - info.append(coroutines._format_coroutine(self._coro)) + coro = coroutines._format_coroutine(self._coro) + info.append('coro=<%s>' % coro) + + if self._source_traceback: + frame = self._source_traceback[-1] + info.append('created at %s:%s' % (frame[0], frame[1])) if self._state == futures._FINISHED: info.append(self._format_result()) |