fix(compat): replace deprecated asyncio.get_event_loop() with get_running_loop()#15
fix(compat): replace deprecated asyncio.get_event_loop() with get_running_loop()#15
Conversation
GA-009: Fix asyncio deprecation for Python 3.12+ - asyncio.get_event_loop() is deprecated since Python 3.10 and raises DeprecationWarning on 3.12+, potentially RuntimeError on 3.14+ - All 4 call sites are inside async functions where a running loop is guaranteed, so get_running_loop() is the correct replacement. - Files: lifecycle.py, connect.py, registration.py, health.py
|
✅ Integration tests passed! capiscio-core gRPC tests working. |
There was a problem hiding this comment.
Pull request overview
This PR updates capiscio-mcp’s async compatibility for Python 3.12+ by replacing deprecated asyncio.get_event_loop() usage with asyncio.get_running_loop() in async contexts, preventing deprecation warnings now and avoiding future runtime failures when no event loop is set.
Changes:
- Replaced
asyncio.get_event_loop()withasyncio.get_running_loop()in async wrappers that dispatch blocking work to a thread pool. - Updated
wait_healthy()timing logic to use the running loop’s monotonic clock viaget_running_loop().time(). - Ensured no remaining
get_event_loop()usages undercapiscio_mcp/.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| capiscio_mcp/registration.py | Uses get_running_loop() before run_in_executor() in register_server_identity() async wrapper. |
| capiscio_mcp/connect.py | Uses get_running_loop() before run_in_executor() in _issue_badge() async wrapper. |
| capiscio_mcp/_core/lifecycle.py | Uses get_running_loop() before run_in_executor() in ensure_binary() async wrapper. |
| capiscio_mcp/_core/health.py | Uses get_running_loop().time() for timeout tracking in wait_healthy(). |
| start_time = asyncio.get_running_loop().time() | ||
| last_error = None | ||
|
|
||
| while (asyncio.get_event_loop().time() - start_time) < timeout: | ||
| while (asyncio.get_running_loop().time() - start_time) < timeout: |
There was a problem hiding this comment.
asyncio.get_running_loop() is called repeatedly in the loop condition. Since the running loop cannot change within this coroutine, consider storing it once (e.g., loop = asyncio.get_running_loop()) and reusing loop.time() for both start_time and the timeout check to avoid repeated lookups and keep the code clearer.
Store asyncio.get_running_loop() once instead of calling it repeatedly in the loop condition.
|
✅ Integration tests passed! capiscio-core gRPC tests working. |
GA-009: Fix asyncio deprecation for Python 3.12+
Priority: P0 — runtime crash on Python 3.12+
Problem
All 4 files used
asyncio.get_event_loop()which is deprecated since Python 3.10 and raisesDeprecationWarningon 3.12+. On Python 3.14+, this will raiseRuntimeErrorin contexts without a running event loop.Fix
Replaced all 5 calls with
asyncio.get_running_loop(). All call sites are insideasyncfunctions where a running loop is guaranteed, makingget_running_loop()the correct and forward-compatible API.Files Changed
capiscio_mcp/_core/lifecycle.py(1 call)capiscio_mcp/connect.py(1 call)capiscio_mcp/registration.py(1 call)capiscio_mcp/_core/health.py(2 calls)Verification
grep -rn "get_event_loop()" capiscio_mcp/returns no matches