()
| 511 | if timeout is not None: |
| 512 | |
| 513 | def timeout_callback() -> None: |
| 514 | # If we can cancel the future, do so and wait on it. If not, |
| 515 | # Just stop the loop and return with the task still pending. |
| 516 | # (If we neither cancel nor wait for the task, a warning |
| 517 | # will be logged). |
| 518 | assert future_cell[0] is not None |
| 519 | if not future_cell[0].cancel(): |
| 520 | self.stop() |
| 521 | |
| 522 | timeout_handle = self.add_timeout(self.time() + timeout, timeout_callback) |
| 523 | self.start() |