Schedules a callback on the ``IOLoop`` when the given `.Future` is finished. The callback is invoked with one argument, the `.Future`. This method only accepts `.Future` objects and not other awaitables (unlike most of Tornado where the two are inter
(
self,
future: "Union[Future[_T], concurrent.futures.Future[_T]]",
callback: Callable[["Future[_T]"], None],
)
| 663 | self.add_callback(callback, *args, **kwargs) |
| 664 | |
| 665 | def add_future( |
| 666 | self, |
| 667 | future: "Union[Future[_T], concurrent.futures.Future[_T]]", |
| 668 | callback: Callable[["Future[_T]"], None], |
| 669 | ) -> None: |
| 670 | """Schedules a callback on the ``IOLoop`` when the given |
| 671 | `.Future` is finished. |
| 672 | |
| 673 | The callback is invoked with one argument, the |
| 674 | `.Future`. |
| 675 | |
| 676 | This method only accepts `.Future` objects and not other |
| 677 | awaitables (unlike most of Tornado where the two are |
| 678 | interchangeable). |
| 679 | """ |
| 680 | if isinstance(future, Future): |
| 681 | # Note that we specifically do not want the inline behavior of |
| 682 | # tornado.concurrent.future_add_done_callback. We always want |
| 683 | # this callback scheduled on the next IOLoop iteration (which |
| 684 | # asyncio.Future always does). |
| 685 | # |
| 686 | # Wrap the callback in self._run_callback so we control |
| 687 | # the error logging (i.e. it goes to tornado.log.app_log |
| 688 | # instead of asyncio's log). |
| 689 | future.add_done_callback( |
| 690 | lambda f: self._run_callback(functools.partial(callback, future)) |
| 691 | ) |
| 692 | else: |
| 693 | assert is_future(future) |
| 694 | # For concurrent futures, we use self.add_callback, so |
| 695 | # it's fine if future_add_done_callback inlines that call. |
| 696 | future_add_done_callback( |
| 697 | future, lambda f: self.add_callback(callback, future) |
| 698 | ) |
| 699 | |
| 700 | def run_in_executor( |
| 701 | self, |