Skip to content
Snippets Groups Projects
Commit 05f701c6 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

async.TaskThread has a waitUntilIdle method, which causes calling thread to

block until queue is empty. ImageWrapper has method to access TaskThread. This
is primarily used for testing threaded access to ImageWrapper.
parent ea2fa09c
No related branches found
No related tags found
No related merge requests found
...@@ -229,6 +229,15 @@ class ImageWrapper(notifier.Notifier): ...@@ -229,6 +229,15 @@ class ImageWrapper(notifier.Notifier):
self.__taskThraed = None self.__taskThraed = None
def getTaskThread(self):
"""If this ``ImageWrapper`` was created with ``threaded=True``,
this method returns the ``TaskThread`` that is used for running
data range calculation tasks. Otherwise, this method returns
``False``.
"""
return self.__taskThread
def reset(self, dataRange=None): def reset(self, dataRange=None):
"""Reset the internal state and known data range of this """Reset the internal state and known data range of this
``ImageWrapper``. ``ImageWrapper``.
...@@ -745,9 +754,9 @@ def isValidFancySliceObj(sliceobj, shape): ...@@ -745,9 +754,9 @@ def isValidFancySliceObj(sliceobj, shape):
object. object.
``nibabel`` refers to slice objects as "fancy" if they comprise anything ``nibabel`` refers to slice objects as "fancy" if they comprise anything
but tuples of simple ``slice`` objects. The ``ImageWrapper`` class but tuples of integers and simple ``slice`` objects. The ``ImageWrapper``
supports one type of "fancy" slicing, where the ``sliceobj`` is a boolean class supports one type of "fancy" slicing, where the ``sliceobj`` is a
``numpy`` array of the same shape as the image. boolean ``numpy`` array of the same shape as the image.
This function returns ``True`` if the given ``sliceobj`` adheres to these This function returns ``True`` if the given ``sliceobj`` adheres to these
requirements, ``False`` otherwise. requirements, ``False`` otherwise.
......
...@@ -679,6 +679,12 @@ class TaskThread(threading.Thread): ...@@ -679,6 +679,12 @@ class TaskThread(threading.Thread):
self.__stop = True self.__stop = True
def waitUntilIdle(self):
"""Causes the calling thread to block until the task queue is empty.
"""
self.__q.join()
def run(self): def run(self):
"""Run the ``TaskThread``. """ """Run the ``TaskThread``. """
...@@ -703,6 +709,7 @@ class TaskThread(threading.Thread): ...@@ -703,6 +709,7 @@ class TaskThread(threading.Thread):
self.__enqueued.pop(task.name, None) self.__enqueued.pop(task.name, None)
if not task.enabled: if not task.enabled:
self.__q.task_done()
continue continue
log.debug('Running task: {} [{}]'.format( log.debug('Running task: {} [{}]'.format(
...@@ -733,6 +740,8 @@ class TaskThread(threading.Thread): ...@@ -733,6 +740,8 @@ class TaskThread(threading.Thread):
type(e).__name__, type(e).__name__,
str(e)), str(e)),
exc_info=True) exc_info=True)
finally:
self.__q.task_done()
self.__q = None self.__q = None
self.__enqueued = None self.__enqueued = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment