diff --git a/asyncio/futures.py b/asyncio/futures.py index 166bc80..28fdee4 100644 --- a/asyncio/futures.py +++ b/asyncio/futures.py @@ -14,6 +14,8 @@ from . import compat from . import events +from .log import logger + # States for Future. _PENDING = 'PENDING' _CANCELLED = 'CANCELLED' @@ -212,7 +214,16 @@ def __del__(self): } if self._source_traceback: context['source_traceback'] = self._source_traceback - self._loop.call_exception_handler(context) + + try: + self._loop.call_exception_handler(context) + except BaseException as ex: + logger.error( + 'BaseException in Future.__del__, will be re-raised soon', + exc_info=True) + def throw(): + raise ex + self._loop.call_soon(throw) def cancel(self): """Cancel the future and schedule callbacks.