Skip to content

Commit

Permalink
feat(reconnect): wait on reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
mandrewcito committed Sep 6, 2024
1 parent 9b1cf61 commit 267e653
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
with open("README.md", "r") as fh:
long_description = fh.read()

description = """ A Python SignalR Core client(json and messagepack), with invocation auth and two way streaming.
Compatible with azure / serverless functions. Also with automatic reconnect and manually reconnect"""

setuptools.setup(
name="signalrcore",
version="0.9.6",
author="mandrewcito",
author_email="anbaalo@gmail.com",
description="A Python SignalR Core client(json and messagepack), with invocation auth and two way streaming. Compatible with azure / serverless functions. Also with automatic reconnect and manually reconnect.",
description=description,
keywords="signalr core client 3.1",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
8 changes: 5 additions & 3 deletions signalrcore/transport/websockets/websocket_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ def on_message(self, app, raw_message):
raise ex

def send(self, message):
if self.reconnection_handler:
while self.reconnection_handler.reconnecting:
time.sleep(1)
return self.state.send(message)

def _send(self, message):
Expand Down Expand Up @@ -391,12 +394,11 @@ def on_reconnect(self):
self.logger.debug("-- web socket reconnecting --")

def handle_reconnect(self, sleep: int = 5) -> None:
self.context.reconnection_handler.reconnecting = True

if sleep:
time.sleep(sleep)


self.context.reconnection_handler.reconnecting = True

try:
self.context.dispose()
self.context._start()
Expand Down
6 changes: 2 additions & 4 deletions test/reconnection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ def test_reconnect_interval_config(self):
self.assertTrue(self._locks[identifier].acquire(timeout=10))

connection.transport._ws.close(status=1000, reason="Closed".encode("utf-8"))

self.assertRaises(
HubConnectionError,
lambda: connection.send("DisconnectMe", []))
time.sleep(1)
self.assertTrue(connection.transport.reconnection_handler.reconnecting)

self.assertTrue(self._locks[identifier].acquire(timeout=30))

Expand Down

0 comments on commit 267e653

Please sign in to comment.