Skip to content

Commit

Permalink
Use explicit try/finally to ensure loops quit when receiving a signal
Browse files Browse the repository at this point in the history
Fix #114
  • Loading branch information
nicoddemus committed Dec 16, 2015
1 parent 5c9fc59 commit 1f71905
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pytestqt/wait_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ def wait(self):
self.timeout)

def _quit_loop_by_timeout(self):
self._loop.quit()
self._cleanup()
try:
self._cleanup()
finally:
self._loop.quit()

def _cleanup(self):
if self._timer is not None:
Expand Down Expand Up @@ -119,10 +121,12 @@ def _quit_loop_by_signal(self, *args):
"""
quits the event loop and marks that we finished because of a signal.
"""
self.signal_triggered = True
self.args = list(args)
self._loop.quit()
self._cleanup()
try:
self.signal_triggered = True
self.args = list(args)
self._cleanup()
finally:
self._loop.quit()

def _cleanup(self):
super(SignalBlocker, self)._cleanup()
Expand Down Expand Up @@ -171,8 +175,10 @@ def _signal_emitted(self, signal):
"""
self._signals[signal] = True
if all(self._signals.values()):
self.signal_triggered = True
self._loop.quit()
try:
self.signal_triggered = True
finally:
self._loop.quit()


class SignalTimeoutError(Exception):
Expand Down

0 comments on commit 1f71905

Please sign in to comment.