Commit 4c35aff2 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Merge branch 'rel/0.8.4' into 'v0.8'

Rel/0.8.4

See merge request fsl/fsleyes/widgets!51
parents daf828ec 0f7a8758
......@@ -2,6 +2,18 @@ This document contains the ``fsleyes-widgets`` release history in reverse
chronological order.
0.8.4 (Wednesday October 9th 2019)
----------------------------------
Added
^^^^^
* New :meth:`.status.ClearThreaad.die` method, used for testing purposes.
0.8.3 (Friday October 4th 2019)
-------------------------------
......
Copyright 2016-2018 University of Oxford, Oxford, UK
Copyright 2016-2019 University of Oxford, Oxford, UK
The fsleyes-widgets library
Copyright 2016-2018 University of Oxford, Oxford, UK.
Copyright 2016-2019 University of Oxford, Oxford, UK.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......
......@@ -18,7 +18,7 @@ This file is used to store the current ``fsleyes-widgets`` version.
"""
__version__ = '0.8.3'
__version__ = '0.8.4'
from fsleyes_widgets.utils import (WX_PYTHON, # noqa
......
......@@ -202,6 +202,7 @@ class ClearThread(threading.Thread):
self.daemon = True
self.__clearEvent = threading.Event()
self.__vetoEvent = threading.Event()
self.__dieEvent = threading.Event()
self.__timeout = None
......@@ -220,6 +221,27 @@ class ClearThread(threading.Thread):
self.__vetoEvent.set()
def die(self):
"""This method may be used to force the ``ClearThread`` to exit
immediately, rather than when the process exits.
To cleanly kill the ``ClearThread``, follow this procedure::
import fsleyes_widgets.utils.status as status
status._clearThread.die()
status._clearThread.clear(0.1)
status._clearThread.join()
status._clearThread = None
If the :func:`update` function is used again, a new ``ClearThread``
will automatically be started.
"""
self.__dieEvent.set()
def run(self):
"""The ``ClearThread`` function. Infinite loop which waits until
the :meth:`clear` method is called, and then clears the status
......@@ -232,6 +254,9 @@ class ClearThread(threading.Thread):
self.__clearEvent.wait()
self.__clearEvent.clear()
if self.__dieEvent.is_set():
return
# http://bugs.python.org/issue14623
#
# When the main thread exits, daemon threads will
......@@ -240,7 +265,7 @@ class ClearThread(threading.Thread):
# result in errors.
try:
if not self.__clearEvent.wait(self.__timeout) and \
not self.__vetoEvent.isSet():
not self.__vetoEvent.is_set():
log.debug('Timeout - clearing status')
clearStatus()
......
......@@ -76,6 +76,31 @@ def test_clearStatus():
assert target.msg == ''
def test_ClearThread_die():
target = MockTarget()
status.setTarget(target)
# make sure the clearthread is running
status.update('Status1', 1.0)
time.sleep(1.1)
# and can be killed
status._clearThread.die()
status._clearThread.clear(0.1)
status._clearThread.join()
status._clearThread = None
# and then gets restarted again
status.update('Status1', 0.25)
assert target.msg == 'Status1'
time.sleep(0.5)
assert target.msg == ''
def test_reportError():
class MockWX(object):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment