Skip to content

Commit 658d607

Browse files
committed
fix: use blocking GLib main context iteration to prevent CPU busy-spin
GLibEventLoop._iterate_event_loop was calling context.iteration(False), which returns immediately when no events are pending. When process_signals(return_after=...) loops waiting for a signal that takes minutes to arrive (e.g. installation completion in anaconda TUI), this causes a 100% CPU busy-spin. Change the default to blocking iteration (may_block=True) so the GLib context sleeps until a source fires. Add a blocking parameter to the constructor so tests can opt into non-blocking mode. Resolves: rhbz#2344225
1 parent 62f1cd1 commit 658d607

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

‎simpleline/event_loop/glib_event_loop.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@
4343

4444
class GLibEventLoop(AbstractEventLoop):
4545

46-
def __init__(self):
46+
def __init__(self, blocking=True):
4747
super().__init__()
48+
self._blocking = blocking
4849
# Create first loop
4950
loop = GLib.MainLoop()
5051
self._event_loops = [EventLoopData(loop)]
@@ -208,12 +209,9 @@ def process_signals(self, return_after=None):
208209
else:
209210
self._iterate_event_loop(loop_data.loop)
210211

211-
@staticmethod
212-
def _iterate_event_loop(event_loop):
212+
def _iterate_event_loop(self, event_loop):
213213
context = event_loop.get_context()
214-
# This is useful for tests
215-
wait_on_timeout = False
216-
context.iteration(wait_on_timeout)
214+
context.iteration(self._blocking)
217215

218216

219217
class EventLoopData():

‎tests/units/glib/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _quit_loop(self, loop):
4242
def create_glib_loop(self):
4343
# clear flags
4444
self.timeout_error = False
45-
self.loop = GLibEventLoop()
45+
self.loop = GLibEventLoop(blocking=False)
4646

4747
loop = self.loop.active_main_loop
4848
context = loop.get_context()

0 commit comments

Comments
 (0)