mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-21 21:14:17 +02:00
Add timeout to worker cleanup to prevent hanging on Windows
When pytest-xdist terminates worker processes on Windows, the event loop may close before cleanup can complete. Adding a 2-second timeout to the worker cancellation prevents indefinite hanging. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a34b680bb4
commit
53efaeba5b
1 changed files with 5 additions and 3 deletions
|
|
@ -465,10 +465,12 @@ class FastMCP(Generic[LifespanResultT]):
|
|||
try:
|
||||
yield
|
||||
finally:
|
||||
# Cancel worker task on exit
|
||||
# Cancel worker task on exit with timeout to prevent hanging
|
||||
worker_task.cancel()
|
||||
with suppress(asyncio.CancelledError):
|
||||
await worker_task
|
||||
with suppress(
|
||||
asyncio.CancelledError, asyncio.TimeoutError
|
||||
):
|
||||
await asyncio.wait_for(worker_task, timeout=2.0)
|
||||
finally:
|
||||
_current_worker.reset(worker_token)
|
||||
finally:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue