diff --git a/fsl/data/imagewrapper.py b/fsl/data/imagewrapper.py index 066469b332d6c6a1b8ba80183f826d36d19b4612..7f9f86e97d8d474ec89c5c6899ccbdc535cf513c 100644 --- a/fsl/data/imagewrapper.py +++ b/fsl/data/imagewrapper.py @@ -458,7 +458,7 @@ class ImageWrapper(notifier.Notifier): name = '{}_read_{}'.format(id(self), slices) if not self.__taskThread.isQueued(name): self.__taskThread.enqueue( - name, self.__expandCoverage, None, slices) + self.__expandCoverage, slices, taskName=name) def __updateDataRangeOnWrite(self, slices, data): @@ -515,7 +515,7 @@ class ImageWrapper(notifier.Notifier): name = '{}_write_{}'.format(id(self), slices) if not self.__taskThread.isQueued(name): self.__taskThread.enqueue( - name, self.__expandCoverage, None, slices) + self.__expandCoverage, slices, taskName=name) def __getitem__(self, sliceobj): diff --git a/fsl/utils/async.py b/fsl/utils/async.py index 51e6ae5cd396d42947f1984b10f9a96913cb8ef5..c7289b7b9a1f299f2fca795e49ab1fa35af9bd48 100644 --- a/fsl/utils/async.py +++ b/fsl/utils/async.py @@ -410,24 +410,36 @@ class TaskThread(threading.Thread): log.debug('New task thread') - def enqueue(self, name, func, onFinish, *args, **kwargs): + def enqueue(self, func, *args, **kwargs): """Enqueue a task to be executed. - :arg name: Task name. Does not necessarily have to be a string, - but must be hashable. :arg func: The task function. + + :arg taskName: Task name. Must be specified as a keyword + argument. Does not necessarily have to be a string, but + must be hashable. If you wish to use the :meth:`dequeue` + or :meth:`isQueued` methods, you must provide a task + name. + :arg onFinish: An optional function to be called (via :func:`idle`) - when the task funtion has finished. + when the task funtion has finished. Must be provided as + a keyword argument. - All other arguments will be passed through to the task when it is + All other arguments are passed through to the task function when it is executed. - .. note:: If the specified ``name`` is not unique (i.e. another task - with the same name may already be enqueued), the + .. note:: If the specified ``taskName`` is not unique (i.e. another + task with the same name may already be enqueued), the :meth:`isQueued` method will probably return invalid results. + + .. warning:: Make sure that your task function is not expecting keyword + arguments called ``taskName`` or ``onFinish``! """ + name = kwargs.pop('taskName', None) + onFinish = kwargs.pop('onFinish', None) + log.debug('Enqueueing task: {} [{}]'.format( name, getattr(func, '__name__', '<unknown>'))) @@ -516,8 +528,6 @@ class TaskThread(threading.Thread): log.debug('Task thread finished') - - def mutex(*args, **kwargs): """Decorator for use on methods of a class, which makes the method call mutually exclusive.