From 2359b49c3e23734bb87e24dd5593a40beb3850be Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Mon, 7 Oct 2019 11:44:00 +0100 Subject: [PATCH] MNT: Hook in idle module to allow errors to be propagated. Useful for testing. --- fsl/utils/idle.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/fsl/utils/idle.py b/fsl/utils/idle.py index f2fc9d0d2..c1184a31a 100644 --- a/fsl/utils/idle.py +++ b/fsl/utils/idle.py @@ -196,6 +196,13 @@ _idleCallRate = 200 """ +_idleAllowErrors = False +"""Used for testing/debugging. If ``True``, and a function called on the idle +loop raises an error, that error will not be caught, and the idle loop will +stop. +""" + + def idleReset(): """Reset the internal :func:`idle` queue state. @@ -211,6 +218,7 @@ def idleReset(): global _idleQueueDict global _idleTimer global _idleCallRate + global _idleAllowErrors if _idleTimer is not None: _idleTimer.Stop() @@ -221,11 +229,12 @@ def idleReset(): if queue is not None: newQueue = queue.Queue() else: newQueue = None - _idleRegistered = False - _idleQueue = newQueue - _idleQueueDict = {} - _idleTimer = None - _idleCallRate = 200 + _idleRegistered = False + _idleQueue = newQueue + _idleQueueDict = {} + _idleTimer = None + _idleCallRate = 200 + _idleAllowErrors = False # Call idleReset on exit, in @@ -294,6 +303,7 @@ def _wxIdleLoop(ev): global _idleQueueDict global _idleTimer global _idleCallRate + global _idleAllowErrors ev.Skip() @@ -342,6 +352,9 @@ def _wxIdleLoop(ev): log.warning('Idle task {} crashed - {}: {}'.format( taskName, type(e).__name__, str(e)), exc_info=True) + if _idleAllowErrors: + raise e + if task.name is not None: try: _idleQueueDict.pop(task.name) except KeyError: pass -- GitLab