fix: guard connection-state callbacks against no running event loop
The previous hotfix's disconnect()-on-comm-error path can now fire during server/brewpi.py's own final best-effort hardware-release cleanup (finally: block's heater.close()/stirrer.activate(False)), which runs after the event loop has already stopped - previously nothing about hardware teardown touched an AttributeChange-tracked field, so this path was dormant. asyncio.create_task() there raises RuntimeError: no running event loop, crashing the shutdown sequence. Adds fire_and_forget() (tasks/task.py) - asyncio.create_task() that silently drops the message instead of raising when there's no loop to schedule on - and uses it for the Connected/FirmwareVersion broadcasts. SudTask.check_connections() also now no-ops entirely without a running loop, since self.sud.stop() cascades into further unguarded create_task() calls (on_state_changed, heater_task.shutdown(), ...) that a stopped loop can't help with anyway. Reproduced and verified fixed directly against HeaterTask/HeaterHendi with no event loop running (mirrors the exact server/brewpi.py shutdown-time call path that crashed on the brewpi Pi). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YaPLuRPpyjWcwhMvCvpHCL
This commit is contained in:
+3
-3
@@ -1,5 +1,5 @@
|
||||
import asyncio
|
||||
from tasks import ATask
|
||||
from tasks import ATask, fire_and_forget
|
||||
from ws.message import MsgIo
|
||||
from components import AStirrer
|
||||
from utils.value import ChangedInteger
|
||||
@@ -34,12 +34,12 @@ class StirrerTask(ATask):
|
||||
self._on_connected_changed = callback
|
||||
|
||||
def on_connected_changed(self, value):
|
||||
asyncio.create_task(self.send({'Connected': value}))
|
||||
fire_and_forget(self.send({'Connected': value}))
|
||||
if self._on_connected_changed:
|
||||
self._on_connected_changed(value)
|
||||
|
||||
def on_firmware_version_changed(self, value):
|
||||
asyncio.create_task(self.send({'FirmwareVersion': value}))
|
||||
fire_and_forget(self.send({'FirmwareVersion': value}))
|
||||
|
||||
async def recv(self, data):
|
||||
for pair in data.items():
|
||||
|
||||
Reference in New Issue
Block a user