(self, exc)
| 281 | self = None # Needed to break cycles when an exception occurs. |
| 282 | |
| 283 | def __step_run_and_handle_result(self, exc): |
| 284 | coro = self._coro |
| 285 | try: |
| 286 | if exc is None: |
| 287 | # We use the `send` method directly, because coroutines |
| 288 | # don't have `__iter__` and `__next__` methods. |
| 289 | result = coro.send(None) |
| 290 | else: |
| 291 | result = coro.throw(exc) |
| 292 | except StopIteration as exc: |
| 293 | if self._must_cancel: |
| 294 | # Task is cancelled right before coro stops. |
| 295 | self._must_cancel = False |
| 296 | super().cancel(msg=self._cancel_message) |
| 297 | else: |
| 298 | super().set_result(exc.value) |
| 299 | except exceptions.CancelledError as exc: |
| 300 | # Save the original exception so we can chain it later. |
| 301 | self._cancelled_exc = exc |
| 302 | super().cancel() # I.e., Future.cancel(self). |
| 303 | except (KeyboardInterrupt, SystemExit) as exc: |
| 304 | super().set_exception(exc) |
| 305 | raise |
| 306 | except BaseException as exc: |
| 307 | super().set_exception(exc) |
| 308 | else: |
| 309 | blocking = getattr(result, '_asyncio_future_blocking', None) |
| 310 | if blocking is not None: |
| 311 | # Yielded Future must come from Future.__iter__(). |
| 312 | if futures._get_loop(result) is not self._loop: |
| 313 | new_exc = RuntimeError( |
| 314 | f'Task {self!r} got Future ' |
| 315 | f'{result!r} attached to a different loop') |
| 316 | self._loop.call_soon( |
| 317 | self.__step, new_exc, context=self._context) |
| 318 | elif blocking: |
| 319 | if result is self: |
| 320 | new_exc = RuntimeError( |
| 321 | f'Task cannot await on itself: {self!r}') |
| 322 | self._loop.call_soon( |
| 323 | self.__step, new_exc, context=self._context) |
| 324 | else: |
| 325 | futures.future_add_to_awaited_by(result, self) |
| 326 | result._asyncio_future_blocking = False |
| 327 | result.add_done_callback( |
| 328 | self.__wakeup, context=self._context) |
| 329 | self._fut_waiter = result |
| 330 | if self._must_cancel: |
| 331 | if self._fut_waiter.cancel( |
| 332 | msg=self._cancel_message): |
| 333 | self._must_cancel = False |
| 334 | else: |
| 335 | new_exc = RuntimeError( |
| 336 | f'yield was used instead of yield from ' |
| 337 | f'in task {self!r} with {result!r}') |
| 338 | self._loop.call_soon( |
| 339 | self.__step, new_exc, context=self._context) |
| 340 |
no test coverage detected