From 536499ddb13c807012bde3a208b0a89c35b36611 Mon Sep 17 00:00:00 2001 From: Ketok Date: Thu, 25 Jan 2024 21:51:00 +0100 Subject: [PATCH] Fix a bug --- src/test_worker.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/test_worker.py b/src/test_worker.py index 8efd1f8..0646b5c 100644 --- a/src/test_worker.py +++ b/src/test_worker.py @@ -26,6 +26,7 @@ def __init__(self, app, server): self.start_time = 0 self.last_label_update = 0 + self.unsignal = None def run(self): event_loop = asyncio.new_event_loop() @@ -39,6 +40,7 @@ async def run_async(self): while not task.done(): if self.stop_event.is_set(): + if self.unsignal: GLib.idle_add(self.unsignal) task.cancel() break @@ -55,16 +57,13 @@ async def do_run(self): try: view = self.app.win.test_view - timeout = None - def on_event(type): - nonlocal timeout - if type == "ping": view.ping = f"{self.results.ping:.1f}ms" view.jitter = f"{self.results.jitter:.1f}ms" elif type == "download_start": - timeout = view.download.get_frame_clock().connect("before-paint", lambda *_: self.update(view.download, self.results.total_dl, False)) + signal = view.download.get_frame_clock().connect("before-paint", lambda *_: self.update(view.download, self.results.total_dl, False)) + self.unsignal = lambda: view.download.get_frame_clock().disconnect(signal) view.progress.remove_css_class("up") view.progress.add_css_class("dl") @@ -72,10 +71,11 @@ def on_event(type): self.start_time = time.time() elif type == "download_end": - view.download.get_frame_clock().disconnect(timeout) + self.unsignal() view.download.remove_css_class("active") elif type == "upload_start": - timeout = view.upload.get_frame_clock().connect("before-paint", lambda *_: self.update(view.upload, self.results.total_up, True)) + signal = view.upload.get_frame_clock().connect("before-paint", lambda *_: self.update(view.upload, self.results.total_up, True)) + self.unsignal = lambda: view.upload.get_frame_clock().disconnect(signal) view.progress.remove_css_class("dl") view.progress.add_css_class("up") @@ -83,7 +83,7 @@ def on_event(type): self.start_time = time.time() elif type == "upload_end": - view.upload.get_frame_clock().disconnect(timeout) + self.unsignal() view.upload.remove_css_class("active") GLib.idle_add(self.app.win.test_view.progress.set_visible, True) @@ -108,12 +108,3 @@ def update(self, gauge, total, part_two): gauge.fill = min(speedMb / self.app.settings.get_int("gauge-scale"), 1.0) view.progress.set_fraction(current_duration / DURATION * 0.5 + (0.5 if part_two else 0.0)) - - return not self.stop_event.is_set() - - async def perform_test(self, test, streams): - GLib.idle_add(self.app.win.test_view.progress.set_visible, True) - - self.start_time = time.time() - - GLib.idle_add(self.app.win.test_view.progress.set_visible, False)