Add control connection for multiplexed WebSocket operations#13
Merged
Conversation
- Add ControlConnection and OpConn classes for control endpoint - Add control_mode client option to enable control mode - Add Sprite.use_control_mode(), get_control_connection(), close_control_connection() - Export new types from __init__.py - Add unit tests for control mode functionality
- Implement ControlPool with acquire/release semantics for connection reuse - Add persistent event loop (loop.py) for sync API connection reuse - Enable control mode by default in client - Fix race condition: remove op_active check in start_op (pool manages it) - Release connections back to pool after each operation
- Add proper close sequence in ControlConnection.close(): close websocket, call wait_closed(), then wait for read task to finish naturally - Add close_timeout=2 to websockets.connect() for faster close handshake - Add _cancel_all_tasks() to loop.py to cancel pending tasks before stopping - Update stop_loop() to cancel all pending tasks before stopping the event loop This fixes the "Task was destroyed but it is pending" warnings from the websockets library's internal keepalive tasks.
Control mode is enabled by default for efficient connection reuse. Updated tests to expect True when control_mode is not specified.
This was referenced Feb 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
control.pymodule implementing control WebSocket protocol for multiplexed operationsSprite.exec()methodKey Changes
src/sprites/control.py- Control connection implementation (662 lines)src/sprites/loop.py- Event loop management for mixing sync/async codesrc/sprites/websocket.py- WebSocket wrapper with ping/pong handlingsrc/sprites/sprite.py- Integration with exec methodtests/test_control.py- Unit tests for control protocolPool Configuration
Related
Part of feature/control-wss-239 work in sprite-env.