Skip to content
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

Upgrade websockets lib to v14 #388

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compute_horde/compute_horde/transport/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
url: str,
*,
max_retries: int = 5,
base_retry_delay: int = 1,
base_retry_delay: float = 1,
retry_jitter: float = 1,
):
super().__init__(name)
Expand All @@ -53,10 +53,10 @@ def __init__(
self.retry_jitter = retry_jitter
self.max_retries = max_retries
self.connect_lock = asyncio.Lock()
self._ws: websockets.WebSocketClientProtocol | None = None
self._ws: websockets.ClientConnection | None = None

@property
def ws(self) -> websockets.WebSocketClientProtocol:
def ws(self) -> websockets.ClientConnection:
if self._ws is None:
raise RuntimeError("WebSocket connection has not been established")
return self._ws
Expand All @@ -70,11 +70,11 @@ async def start(self) -> None:

async def stop(self) -> None:
async with self.connect_lock:
if self._ws and self._ws.open:
if self._ws and self._ws.state is websockets.State.OPEN:
await self._ws.close()

async def connect(self):
if self._ws and self._ws.open:
if self._ws and self._ws.state is websockets.State.OPEN:
return

loop = asyncio.get_running_loop()
Expand Down
2 changes: 1 addition & 1 deletion compute_horde/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ requires-python = "==3.11.*"
dependencies = [
"pydantic<3,>=2.3",
"bittensor<9.0.0,>=8.3.1",
"websockets<14.0,>=13.0",
"websockets>=14.0,<15.0",
"more-itertools>=10.2.0",
"phx-class-registry>=4.1.0",
"requests>=2.32.2",
Expand Down
12 changes: 6 additions & 6 deletions compute_horde/tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class WSTestServer:
port = 8765

def __init__(self):
self.ws_server = None
self.ws_server: websockets.Server | None = None
self.received: asyncio.Queue[str] = asyncio.Queue()

async def srv(self, ws, path):
async def srv(self, ws: websockets.ServerConnection):
async for message in ws:
await self.received.put(message)

Expand All @@ -34,17 +34,17 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.stop()

@property
def connection(self) -> websockets.WebSocketServerProtocol | None:
assert len(self.ws_server.websockets) <= 1
def connection(self) -> websockets.ServerConnection | None:
assert len(self.ws_server.connections) <= 1

try:
return next(iter(self.ws_server.websockets))
return next(iter(self.ws_server.connections))
except StopIteration:
return None

@property
def is_connected(self) -> bool:
return self.connection is not None and self.connection.open
return self.connection is not None and self.connection.state is websockets.State.OPEN


@pytest_asyncio.fixture
Expand Down
34 changes: 17 additions & 17 deletions compute_horde/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion executor/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = [
"nox==2024.10.09",
"httpx~=0.26.0",
"channels[daphne]==4.*",
"websockets==13.*",
"websockets>=14.0,<15.0",
"compute-horde",
"prometheus-client~=0.17.0",
"django-prometheus==2.3.1",
Expand Down
32 changes: 16 additions & 16 deletions executor/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading