asyncio: sync with Tulip

- Issues #21936, #21163: Fix sporadic failures of
  test_future_exception_never_retrieved()
- Handle.cancel() now clears references to callback and args
- In debug mode, repr(Handle) now contains the location where the Handle was
  created.
This commit is contained in:
Victor Stinner 2014-07-10 22:32:58 +02:00
parent eb43214427
commit f68bd88aa6
3 changed files with 74 additions and 16 deletions

View file

@ -82,14 +82,20 @@ class Handle:
self._source_traceback = None
def __repr__(self):
info = []
info = [self.__class__.__name__]
if self._cancelled:
info.append('cancelled')
info.append(_format_callback(self._callback, self._args))
return '<%s %s>' % (self.__class__.__name__, ' '.join(info))
if self._callback is not None:
info.append(_format_callback(self._callback, self._args))
if self._source_traceback:
frame = self._source_traceback[-1]
info.append('created at %s:%s' % (frame[0], frame[1]))
return '<%s>' % ' '.join(info)
def cancel(self):
self._cancelled = True
self._callback = None
self._args = None
def _run(self):
try:
@ -125,7 +131,11 @@ class TimerHandle(Handle):
if self._cancelled:
info.append('cancelled')
info.append('when=%s' % self._when)
info.append(_format_callback(self._callback, self._args))
if self._callback is not None:
info.append(_format_callback(self._callback, self._args))
if self._source_traceback:
frame = self._source_traceback[-1]
info.append('created at %s:%s' % (frame[0], frame[1]))
return '<%s %s>' % (self.__class__.__name__, ' '.join(info))
def __hash__(self):