Skip to content

RuntimeError: Event loop is closed during shutdown #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rubyan opened this issue May 1, 2025 · 1 comment
Open

RuntimeError: Event loop is closed during shutdown #136

rubyan opened this issue May 1, 2025 · 1 comment

Comments

@rubyan
Copy link

rubyan commented May 1, 2025

Hi,
I'm encountering a RuntimeError: Event loop is closed when running a simple sample agent using FastAgent:
`import asyncio
from mcp_agent.core.fastagent import FastAgent

Create the application

fast = FastAgent("FastAgent Example")

Define the agent

@fast.agent(instruction="Given an object, respond only with an estimate of it's size. Treat absoultely any input as an object that you have to size.", servers=["fetch"])
async def main():
# use the --model command line switch or agent arguments to change model
async with fast.run() as agent:
result = await agent("A car")
print(result)

if name == "main":
asyncio.run(main())
`

The main logic of the agent completes successfully, but the error appears during the final cleanup phase after asyncio.run() finishes.

Traceback:

Exception ignored in: <function BaseSubprocessTransport.del at 0x0000021355069EE0> # Example address, replace if needed
Traceback (most recent call last):
File "c:\Program Files\Python311\Lib\asyncio\base_subprocess.py", line 126, in del
self.close()
File "c:\Program Files\Python311\Lib\asyncio\base_subprocess.py", line 104, in close
proto.pipe.close()
File "c:\Program Files\Python311\Lib\asyncio\proactor_events.py", line 109, in close
self._loop.call_soon(self._call_connection_lost, None)
File "c:\Program Files\Python311\Lib\asyncio\base_events.py", line 761, in call_soon
self._check_closed()
File "c:\Program Files\Python311\Lib\asyncio\base_events.py", line 519, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Version: 0.2.19

Thanks!

@evalstate
Copy link
Owner

Hi there - I think this happens when you include Python based MCP Servers - so if for example you didn't reference fetch the stacktrace wouldn't print. I've spent quite a bit of time on this in the past, but for the moment I'm tracking the following items in the Python SDK in hope of remedy:

modelcontextprotocol/python-sdk#552
modelcontextprotocol/python-sdk#596
modelcontextprotocol/python-sdk#577
modelcontextprotocol/python-sdk#514

This stacktrace shouldn't be impacting the operation of fast-agent but let me know if it's causing a problem. The other option is to run under WSL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants