|
7 | 7 |
|
8 | 8 | import cbor2 |
9 | 9 | import pyarrow |
10 | | -from websockets.protocol import State |
11 | | -from websockets.sync.client import ClientConnection |
| 10 | +import websockets.exceptions |
| 11 | +import websockets.protocol |
| 12 | +import websockets.sync.client |
12 | 13 |
|
13 | 14 | from wherobots.db.constants import ( |
14 | 15 | RequestKind, |
@@ -47,7 +48,7 @@ class Connection: |
47 | 48 | corresponding query state. Queries are tracked by their unique execution ID. |
48 | 49 | """ |
49 | 50 |
|
50 | | - def __init__(self, ws: ClientConnection): |
| 51 | + def __init__(self, ws: websockets.sync.client.ClientConnection): |
51 | 52 | self.__ws = ws |
52 | 53 | self.__queries: dict[str, Query] = {} |
53 | 54 | self.__thread = threading.Thread( |
@@ -75,11 +76,15 @@ def cursor(self) -> Cursor: |
75 | 76 |
|
76 | 77 | def __main_loop(self): |
77 | 78 | """Main background loop listening for messages from the SQL session.""" |
78 | | - while self.__ws.protocol.state < State.CLOSING: |
| 79 | + logging.debug("Starting background connection handling loop...") |
| 80 | + while self.__ws.protocol.state < websockets.protocol.State.CLOSING: |
79 | 81 | try: |
80 | 82 | self.__listen() |
| 83 | + except websockets.exceptions.ConnectionClosedOK: |
| 84 | + logging.debug("Connection closed; stopping main loop.") |
| 85 | + return |
81 | 86 | except Exception as e: |
82 | | - logging.exception("Error handling message from SQL session", e) |
| 87 | + logging.exception("Error handling message from SQL session", exc_info=e) |
83 | 88 |
|
84 | 89 | def __listen(self): |
85 | 90 | """Waits for the next message from the SQL session and processes it. |
|
0 commit comments