Skip to content

Commit 3a6f8df

Browse files
committed
Add unsubscribe for events (#52)
1 parent b6b285c commit 3a6f8df

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

singlestoredb/mysql/connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ def close(self):
729729
return
730730
if self._closed:
731731
raise err.Error('Already closed')
732+
events.unsubscribe(self._handle_event)
732733
self._closed = True
733734
if self._sock is None:
734735
return

singlestoredb/utils/events.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ def subscribe(func: Callable[[Dict[str, Any]], None]) -> None:
2727
_subscribers.add(func)
2828

2929

30+
def unsubscribe(func: Callable[[Dict[str, Any]], None]) -> None:
31+
"""
32+
Unsubscribe from SingleStore portal events.
33+
34+
Parameters
35+
----------
36+
func : Callable
37+
The function to call when an event is received
38+
39+
"""
40+
try:
41+
_subscribers.remove(func)
42+
except KeyError:
43+
pass
44+
45+
3046
def _event_handler(stream: Any, ident: Any, msg: Dict[str, Any]) -> None:
3147
"""Handle request on the control stream."""
3248
if not _subscribers or not isinstance(msg, dict):

0 commit comments

Comments
 (0)