Skip to content

Commit ee57456

Browse files
author
Aman Rusia
committed
fixup! Catching one more exception for client retry
1 parent 594b0ac commit ee57456

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/wcgw/client/tools.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
import threading
1111
import importlib.metadata
12+
import time
1213
import traceback
1314
from typing import (
1415
Callable,
@@ -755,16 +756,16 @@ def register_client(server_url: str, client_uuid: str = "") -> None:
755756
client_uuid = str(uuid.uuid4())
756757

757758
# Create the WebSocket connection
758-
with syncconnect(f"{server_url}/{client_uuid}") as websocket:
759-
server_version = str(websocket.recv())
760-
print(f"Server version: {server_version}")
761-
client_version = importlib.metadata.version("wcgw")
762-
websocket.send(client_version)
763-
764-
print(
765-
f"Connected. Share this user id with the chatbot: {client_uuid} \nLink: https://chatgpt.com/g/g-Us0AAXkRh-wcgw-giving-shell-access"
766-
)
767-
try:
759+
try:
760+
with syncconnect(f"{server_url}/{client_uuid}") as websocket:
761+
server_version = str(websocket.recv())
762+
print(f"Server version: {server_version}")
763+
client_version = importlib.metadata.version("wcgw")
764+
websocket.send(client_version)
765+
766+
print(
767+
f"Connected. Share this user id with the chatbot: {client_uuid} \nLink: https://chatgpt.com/g/g-Us0AAXkRh-wcgw-giving-shell-access"
768+
)
768769
while True:
769770
# Wait to receive data from the server
770771
message = websocket.recv()
@@ -783,9 +784,10 @@ def register_client(server_url: str, client_uuid: str = "") -> None:
783784
assert isinstance(output, str)
784785
websocket.send(output)
785786

786-
except (websockets.ConnectionClosed, ConnectionError, OSError):
787-
print(f"Connection closed for UUID: {client_uuid}, retrying")
788-
register_client(server_url, client_uuid)
787+
except (websockets.ConnectionClosed, ConnectionError, OSError):
788+
print(f"Connection closed for UUID: {client_uuid}, retrying")
789+
time.sleep(0.5)
790+
register_client(server_url, client_uuid)
789791

790792

791793
run = Typer(pretty_exceptions_show_locals=False, no_args_is_help=True)

0 commit comments

Comments
 (0)