| 345 | self = None # Needed to break cycles when an exception occurs. |
| 346 | |
| 347 | def __wakeup(self, future): |
| 348 | try: |
| 349 | future.result() |
| 350 | except BaseException as exc: |
| 351 | # This may also be a cancellation. |
| 352 | self.__step(exc) |
| 353 | else: |
| 354 | # Don't pass the value of `future.result()` explicitly, |
| 355 | # as `Future.__iter__` and `Future.__await__` don't need it. |
| 356 | # If we call `_step(value, None)` instead of `_step()`, |
| 357 | # Python eval loop would use `.send(value)` method call, |
| 358 | # instead of `__next__()`, which is slower for futures |
| 359 | # that return non-generator iterators from their `__iter__`. |
| 360 | self.__step() |
| 361 | self = None # Needed to break cycles when an exception occurs. |
| 362 | |
| 363 | |
| 364 | _PyTask = Task |