From e7ba37ec924f5dda998478ad07b46ea1633bf740 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Fri, 6 May 2016 15:12:02 +0100 Subject: [PATCH] Hacky workaround python bug - daemon threads continue to run after threading module has been destroyed. --- fsl/utils/status.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/fsl/utils/status.py b/fsl/utils/status.py index ba658e592..54b6ce6e4 100644 --- a/fsl/utils/status.py +++ b/fsl/utils/status.py @@ -150,14 +150,25 @@ class ClearThread(threading.Thread): (via a call to :func:`clearStatus`). """ - while True: + # http://bugs.python.org/issue14623 + # + # When the main thread exits, daemon threads will + # continue to run after the threading module is + # destroyed. Calls to the Event methods can thus + # result in errors. + try: - self.__vetoEvent .clear() - self.__clearEvent.wait() - self.__clearEvent.clear() + while True: - if not self.__clearEvent.wait(self.__timeout) and \ - not self.__vetoEvent.isSet(): - - log.debug('Timeout - clearing status') - clearStatus() + self.__vetoEvent .clear() + self.__clearEvent.wait() + self.__clearEvent.clear() + + if not self.__clearEvent.wait(self.__timeout) and \ + not self.__vetoEvent.isSet(): + + log.debug('Timeout - clearing status') + clearStatus() + + except: + pass -- GitLab