diff --git a/fsl/data/imagewrapper.py b/fsl/data/imagewrapper.py index 6358a1b679f503d7d263c636fe952ddf5911bbe3..2651e144e6cd4858ef54979e87dca06dd1ecca68 100644 --- a/fsl/data/imagewrapper.py +++ b/fsl/data/imagewrapper.py @@ -180,6 +180,7 @@ class ImageWrapper(notifier.Notifier): if threaded: self.__taskThread = async.TaskThread() + self.__taskThread.daemon = True self.__taskThread.start() diff --git a/fsl/utils/async.py b/fsl/utils/async.py index f704945490163230710d01c6229c820ec2ff56af..9c4f0aab4c5aec53630195699521007551619674 100644 --- a/fsl/utils/async.py +++ b/fsl/utils/async.py @@ -318,17 +318,31 @@ def wait(threads, task, *args, **kwargs): instances to finsih (by ``join``ing them), and then runs the given ``task`` via :func:`idle`. - If a ``wx.App`` is not running, this function ``join``s the threads - directly instead of creating a new ``Thread`` to do so. + If the ``direct`` parameter is ``True``, or a ``wx.App`` is not running, + this function ``join``s the threads directly instead of creating a new + ``Thread`` to do so. - :arg threads: A ``Thread``, or a sequence of ``Thread`` instances to - join. Elements in the sequence may be ``None``. + :arg threads: A ``Thread``, or a sequence of ``Thread`` instances to + join. Elements in the sequence may be ``None``. - :arg task: The task to run. + :arg task: The task to run once all ``threads`` have completed. + + :arg wait_direct: Must be passed as a keyword argument. If ``True``, this + function call will ``join`` all of the ``threads``, and + then call the ``task``. Otherwise (the default), this + function will create a new thread to ``join`` the + ``threads``, and will return immediately. + All other arguments are passed to the ``task`` function. + + + .. note:: This function will not support ``task`` functions which expect + a keyword argument called ``wait_direct``. """ + direct = kwargs.pop('wait_direct', False) + if not isinstance(threads, collections.Sequence): threads = [threads] @@ -343,7 +357,7 @@ def wait(threads, task, *args, **kwargs): log.debug('Wait thread scheduling task on idle loop') idle(task, *args, **kwargs) - if haveWX: + if haveWX and not direct: thread = threading.Thread(target=joinAll) thread.start() return thread