changeset 4295:7d98d894933c

frontends (tools/aio): Fix excessive use of CPU: Use a short delay instead of `loop.call_soonloop.call_soon` when work as been done, as this was resulting in an excessive use of CPU.
author Goffi <goffi@goffi.org>
date Fri, 06 Sep 2024 17:38:31 +0200
parents a0ed5c976bf8
children ffc43219e0b2
files libervia/frontends/tools/aio.py
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/frontends/tools/aio.py	Tue Aug 06 23:43:11 2024 +0200
+++ b/libervia/frontends/tools/aio.py	Fri Sep 06 17:38:31 2024 +0200
@@ -141,8 +141,9 @@
         if iteration_count == 0:
             loop.call_later(0.01, _glib_iteration)
         else:
-            # Schedule ourselves to run again on the next asyncio loop iteration
-            loop.call_soon(_glib_iteration)
+            # Work has been done, and there may still be some. Use a shorter delay to
+            # schedule ourselves again.
+            loop.call_later(0.001, _glib_iteration)
 
     # Kick off the GLib iteration
     loop.call_soon(_glib_iteration)