diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py index 903f934b2f98ce77b06c2dc1736bfaa337b1d375..c149ed93b8997959ab4d0ca58cfaf00f5a00a261 100644 --- a/examples/domain-events/events-python/event-test.py +++ b/examples/domain-events/events-python/event-test.py @@ -92,6 +92,8 @@ class virEventLoopPure: def __init__(self): self.poll = select.poll() self.pipetrick = os.pipe() + self.pendingWakeup = False + self.runningPoll = False self.nextHandleID = 1 self.nextTimerID = 1 self.handles = [] @@ -166,6 +168,7 @@ class virEventLoopPure: # these pointless repeated tiny sleeps. def run_once(self): sleep = -1 + self.runningPoll = True next = self.next_timeout() debug("Next timeout due at %d" % next) if next > 0: @@ -184,6 +187,7 @@ class virEventLoopPure: # telling us to wakup. if so, then discard # the data just continue if fd == self.pipetrick[0]: + self.pendingWakeup = False data = os.read(fd, 1) continue @@ -206,6 +210,8 @@ class virEventLoopPure: t.set_last_fired(now) t.dispatch() + self.runningPoll = False + # Actually the event loop forever def run_loop(self): @@ -214,7 +220,9 @@ class virEventLoopPure: self.run_once() def interrupt(self): - os.write(self.pipetrick[1], 'c') + if self.runningPoll and not self.pendingWakeup: + self.pendingWakeup = True + os.write(self.pipetrick[1], 'c') # Registers a new file handle 'fd', monitoring for 'events' (libvirt