Remove is running loop variable

Just use Task.done()
This commit is contained in:
atse 2023-07-13 15:45:08 +08:00
parent fd83ee23e1
commit 917a2546cc
1 changed files with 1 additions and 4 deletions

View File

@ -36,14 +36,13 @@ class ClientWatcher(QObject):
def __init__(self, parent, client, update_s):
self.update_s = update_s
self.running = False
self.client = client
self.watch_task = None
super().__init__(parent)
async def run(self):
loop = asyncio.get_running_loop()
while self.running:
while True:
time = loop.time()
await self.update_params()
await asyncio.sleep(self.update_s - (loop.time() - time))
@ -52,12 +51,10 @@ class ClientWatcher(QObject):
self.fan_update.emit(await self.client.fan())
def start_watching(self):
self.running = True
self.watch_task = asyncio.create_task(self.run())
@pyqtSlot()
def stop_watching(self):
self.running = False
self.watch_task.cancel()
@pyqtSlot(float)