Skip to content

Commit a2faa95

Browse files
committed
feat: cleanup websocket connection establishment
Additional thread is no longer required since websockets >= 13.0, thanks to our feedback to the upstream project.
1 parent 0304198 commit a2faa95

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

wherobots/db/driver.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -172,32 +172,18 @@ def connect_direct(
172172
q = queue.SimpleQueue()
173173
uri_with_protocol = f"{uri}/{PROTOCOL_VERSION}"
174174

175-
def create_ws_connection():
176-
try:
177-
logging.info("Connecting to SQL session at %s ...", uri_with_protocol)
178-
ws = websockets.sync.client.connect(
179-
uri=uri_with_protocol,
180-
additional_headers=headers,
181-
max_size=MAX_MESSAGE_SIZE,
182-
)
183-
q.put(ws)
184-
except Exception as e:
185-
q.put(e)
186-
187-
dt = threading.Thread(
188-
name="wherobots-ws-connector",
189-
target=create_ws_connection,
190-
daemon=True,
191-
)
192-
dt.start()
193-
dt.join()
194-
195-
result = q.get()
196-
if isinstance(result, Exception):
197-
raise InterfaceError("Failed to connect to SQL session!") from result
175+
try:
176+
logging.info("Connecting to SQL session at %s ...", uri_with_protocol)
177+
ws = websockets.sync.client.connect(
178+
uri=uri_with_protocol,
179+
additional_headers=headers,
180+
max_size=MAX_MESSAGE_SIZE,
181+
)
182+
except Exception as e:
183+
raise InterfaceError("Failed to connect to SQL session!") from e
198184

199185
return Connection(
200-
result,
186+
ws,
201187
read_timeout=read_timeout,
202188
results_format=results_format,
203189
data_compression=data_compression,

0 commit comments

Comments
 (0)