RemoteWorker.cancel makes no coroutine once the loop is closed

run_coroutine_threadsafe refused it and it was never awaited, a RuntimeWarning
under pytest 9. The cancel still logs that it could not reach the worker.
This commit is contained in:
2026-10-15 16:17:30 +02:00
parent 146ab72c17
commit 08adc9ef1d
2 changed files with 22 additions and 0 deletions
+5
View File
@@ -249,6 +249,11 @@ class RemoteWorker:
def cancel(self, call_id: str) -> None:
"""Ask the worker to kill what it is running for this call."""
# A closed loop refuses the coroutine and leaves it never awaited, so it
# is not made at all.
if self._loop.is_closed():
logger.warning("Could not cancel '%s' on '%s'", call_id, self.name)
return
try:
asyncio.run_coroutine_threadsafe(
self._send({"op": "cancel", "call_id": call_id}), self._loop