(call: Callable[[], object], seconds: float)
| 53 | |
| 54 | |
| 55 | def call_within(call: Callable[[], object], seconds: float) -> tuple[bool, BaseException | None]: # pragma: win32 cover |
| 56 | raised: list[BaseException] = [] |
| 57 | |
| 58 | def run() -> None: |
| 59 | try: |
| 60 | call() |
| 61 | except Exception as error: # handed to the caller, which asserts on it |
| 62 | raised.append(error) |
| 63 | |
| 64 | thread = threading.Thread(target=run, daemon=True) |
| 65 | thread.start() |
| 66 | thread.join(seconds) |
| 67 | return not thread.is_alive(), next(iter(raised), None) |
| 68 | |
| 69 | |
| 70 | __all__ = [ |