From 0f14241166a44e232bc9ed8ba77d9a971909d825 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Mon, 21 Oct 2019 15:30:30 +0100 Subject: [PATCH] ENH: Global override in idle loop to force all tasks to be called synchronously --- fsl/utils/idle.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/fsl/utils/idle.py b/fsl/utils/idle.py index 8f2689893..afa6247ae 100644 --- a/fsl/utils/idle.py +++ b/fsl/utils/idle.py @@ -141,6 +141,7 @@ class IdleLoop(object): self.__timer = None self.__callRate = 200 self.__allowErrors = False + self.__neverQueue = False # Call reset on exit, in case # the idle.timer is active. @@ -221,6 +222,20 @@ class IdleLoop(object): self.__allowErrors = allow + @property + def neverQueue(self): + """If ``True``, tasks passed to :meth:`idle` will never be queued, and + instead will always be executed directly/synchonously. + """ + return self.__neverQueue + + + @neverQueue.setter + def neverQueue(self, allow): + """Update the ``neverQueue`` flag. """ + self.__neverQueue = allow + + def reset(self): """Reset the internal idle loop state. @@ -249,6 +264,7 @@ class IdleLoop(object): self.__timer = None self.__callRate = 200 self.__allowErrors = False + self.__neverQueue = False def inIdle(self, taskName): @@ -315,9 +331,11 @@ class IdleLoop(object): All other arguments are passed through to the task function. - If a ``wx.App`` is not running, the ``timeout``, ``name`` and - ``skipIfQueued`` arguments are ignored. Instead, the call will sleep - for ``after`` seconds, and then the ``task`` is called directly. + If a ``wx.App`` is not running, or :meth:`neverQueue` has been set to + ``True``, the ``timeout``, ``name``, ``dropIfQueued``, + ``skipIfQueued``, and ``alwaysQueue`` arguments are ignored. Instead, + the call will sleep for ``after`` seconds, and then the ``task`` will + be called directly. .. note:: If the ``after`` argument is used, there is no guarantee that @@ -347,8 +365,8 @@ class IdleLoop(object): skipIfQueued = kwargs.pop('skipIfQueued', False) alwaysQueue = kwargs.pop('alwaysQueue', False) - canHaveGui = fslplatform.canHaveGui - haveGui = fslplatform.haveGui + canHaveGui = fslplatform.canHaveGui + haveGui = fslplatform.haveGui # If there is no possibility of a # gui being available in the future @@ -358,7 +376,7 @@ class IdleLoop(object): # We don't have wx - run the task # directly/synchronously. - if not (haveGui or alwaysQueue): + if self.__neverQueue or not (haveGui or alwaysQueue): time.sleep(after) log.debug('Running idle task directly') task(*args, **kwargs) -- GitLab