Skip to content

fix(compat): replace deprecated asyncio.get_event_loop() with get_running_loop()#15

Merged
beonde merged 2 commits intomainfrom
fix/ga-asyncio-compat
Apr 17, 2026
Merged

fix(compat): replace deprecated asyncio.get_event_loop() with get_running_loop()#15
beonde merged 2 commits intomainfrom
fix/ga-asyncio-compat

Conversation

@beonde
Copy link
Copy Markdown
Member

@beonde beonde commented Apr 17, 2026

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 raises DeprecationWarning on 3.12+. On Python 3.14+, this will raise RuntimeError in contexts without a running event loop.

Fix

Replaced all 5 calls with asyncio.get_running_loop(). All call sites are inside async functions where a running loop is guaranteed, making get_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
  • Package declares Python 3.13 support — this fix ensures forward compatibility

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
Copilot AI review requested due to automatic review settings April 17, 2026 04:33
@github-actions
Copy link
Copy Markdown

✅ Integration tests passed! capiscio-core gRPC tests working.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() with asyncio.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 via get_running_loop().time().
  • Ensured no remaining get_event_loop() usages under capiscio_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().

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread capiscio_mcp/_core/health.py Outdated
Comment on lines +111 to +114
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:
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Store asyncio.get_running_loop() once instead of calling it
repeatedly in the loop condition.
@github-actions
Copy link
Copy Markdown

✅ Integration tests passed! capiscio-core gRPC tests working.

@beonde beonde merged commit 5cd2ab3 into main Apr 17, 2026
10 checks passed
@beonde beonde deleted the fix/ga-asyncio-compat branch April 17, 2026 04:53
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

Successfully merging this pull request may close these issues.

2 participants