Skip to content

Commit 459bd73

Browse files
authored
fix: cancel async tasks when closing websocket (#417)
1 parent 82626e6 commit 459bd73

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

openevsehttp/__main__.py

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def __init__(self, host: str, user: str = "", pwd: str = "") -> None:
9191
self.websocket: OpenEVSEWebsocket | None = None
9292
self.callback: Callable | None = None
9393
self._loop = None
94+
self.tasks = None
9495

9596
async def process_request(
9697
self,
@@ -295,6 +296,11 @@ async def ws_disconnect(self) -> None:
295296
self._ws_listening = False
296297
assert self.websocket
297298
await self.websocket.close()
299+
if self._loop:
300+
try:
301+
self._loop.cancel()
302+
except AttributeError:
303+
pass
298304

299305
def is_coroutine_function(self, callback):
300306
"""Check if a callback is a coroutine function."""

openevsehttp/websocket.py

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ async def listen(self):
142142
async def close(self):
143143
"""Close the listening websocket."""
144144
await OpenEVSEWebsocket.state.fset(self, STATE_STOPPED)
145+
await self.session.close()
145146

146147
async def keepalive(self):
147148
"""Send ping requests to websocket."""

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
PROJECT_DIR = Path(__file__).parent.resolve()
88
README_FILE = PROJECT_DIR / "README.md"
9-
VERSION = "0.1.75"
9+
VERSION = "0.1.76"
1010

1111
setup(
1212
name="python_openevse_http",

0 commit comments

Comments
 (0)