| 357 | self = None # Needed to break cycles when an exception occurs. |
| 358 | |
| 359 | def __wakeup(self, future): |
| 360 | futures.future_discard_from_awaited_by(future, self) |
| 361 | try: |
| 362 | future.result() |
| 363 | except BaseException as exc: |
| 364 | # This may also be a cancellation. |
| 365 | self.__step(exc) |
| 366 | else: |
| 367 | # Don't pass the value of `future.result()` explicitly, |
| 368 | # as `Future.__iter__` and `Future.__await__` don't need it. |
| 369 | # If we call `__step(value, None)` instead of `__step()`, |
| 370 | # Python eval loop would use `.send(value)` method call, |
| 371 | # instead of `__next__()`, which is slower for futures |
| 372 | # that return non-generator iterators from their `__iter__`. |
| 373 | self.__step() |
| 374 | self = None # Needed to break cycles when an exception occurs. |
| 375 | |
| 376 | |
| 377 | _PyTask = Task |