Runs a callback with error handling. .. versionchanged:: 6.0 CancelledErrors are no longer logged.
(self, callback: Callable[[], Any])
| 748 | self._executor = executor |
| 749 | |
| 750 | def _run_callback(self, callback: Callable[[], Any]) -> None: |
| 751 | """Runs a callback with error handling. |
| 752 | |
| 753 | .. versionchanged:: 6.0 |
| 754 | |
| 755 | CancelledErrors are no longer logged. |
| 756 | """ |
| 757 | try: |
| 758 | ret = callback() |
| 759 | if ret is not None: |
| 760 | from tornado import gen |
| 761 | |
| 762 | # Functions that return Futures typically swallow all |
| 763 | # exceptions and store them in the Future. If a Future |
| 764 | # makes it out to the IOLoop, ensure its exception (if any) |
| 765 | # gets logged too. |
| 766 | try: |
| 767 | ret = gen.convert_yielded(ret) |
| 768 | except gen.BadYieldError: |
| 769 | # It's not unusual for add_callback to be used with |
| 770 | # methods returning a non-None and non-yieldable |
| 771 | # result, which should just be ignored. |
| 772 | pass |
| 773 | else: |
| 774 | self.add_future(ret, self._discard_future_result) |
| 775 | except asyncio.CancelledError: |
| 776 | pass |
| 777 | except Exception: |
| 778 | app_log.error("Exception in callback %r", callback, exc_info=True) |
| 779 | |
| 780 | def _discard_future_result(self, future: Future) -> None: |
| 781 | """Avoid unhandled-exception warnings from spawned coroutines.""" |
no test coverage detected