Skip to content

fix: dispatch realtime events on captured asyncio loop#90

Open
rupurt wants to merge 2 commits into
TexasCoding:mainfrom
rupurt:codex/realtime-thread-loop-dispatch
Open

fix: dispatch realtime events on captured asyncio loop#90
rupurt wants to merge 2 commits into
TexasCoding:mainfrom
rupurt:codex/realtime-thread-loop-dispatch

Conversation

@rupurt

@rupurt rupurt commented Jun 29, 2026

Copy link
Copy Markdown

Summary

  • capture the asyncio event loop before SignalR connection setup starts
  • route realtime and batched market callbacks through the captured loop with run_coroutine_threadsafe
  • drop late SignalR events quietly when the loop is gone instead of trying to create tasks on SignalR threads
  • add regression coverage for active-loop, worker-thread, and missing-loop dispatch paths

Why

SignalR callbacks can run on non-asyncio worker threads. The previous fallback attempted to create asyncio tasks from those threads when the stored loop was missing or closed, which produced repeated No event loop available for market_depth event and quote_update event errors.

Validation

  • uv run pytest tests/realtime/test_event_handling.py -q
  • uv run ruff check src/project_x_py/realtime/event_handling.py src/project_x_py/realtime/connection_management.py tests/realtime/test_event_handling.py

@rupurt rupurt changed the title [codex] dispatch realtime events on captured asyncio loop fix: dispatch realtime events on captured asyncio loop Jun 29, 2026
@rupurt rupurt marked this pull request as ready for review June 29, 2026 03:58
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.

1 participant