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

Adjustment to TaskThread.enqueue - now accepts task name/callback as

keyword arguments.
parent eca48715
No related branches found
No related tags found
No related merge requests found
...@@ -458,7 +458,7 @@ class ImageWrapper(notifier.Notifier): ...@@ -458,7 +458,7 @@ class ImageWrapper(notifier.Notifier):
name = '{}_read_{}'.format(id(self), slices) name = '{}_read_{}'.format(id(self), slices)
if not self.__taskThread.isQueued(name): if not self.__taskThread.isQueued(name):
self.__taskThread.enqueue( self.__taskThread.enqueue(
name, self.__expandCoverage, None, slices) self.__expandCoverage, slices, taskName=name)
def __updateDataRangeOnWrite(self, slices, data): def __updateDataRangeOnWrite(self, slices, data):
...@@ -515,7 +515,7 @@ class ImageWrapper(notifier.Notifier): ...@@ -515,7 +515,7 @@ class ImageWrapper(notifier.Notifier):
name = '{}_write_{}'.format(id(self), slices) name = '{}_write_{}'.format(id(self), slices)
if not self.__taskThread.isQueued(name): if not self.__taskThread.isQueued(name):
self.__taskThread.enqueue( self.__taskThread.enqueue(
name, self.__expandCoverage, None, slices) self.__expandCoverage, slices, taskName=name)
def __getitem__(self, sliceobj): def __getitem__(self, sliceobj):
......
...@@ -410,24 +410,36 @@ class TaskThread(threading.Thread): ...@@ -410,24 +410,36 @@ class TaskThread(threading.Thread):
log.debug('New task 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. """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 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`) :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. executed.
.. note:: If the specified ``name`` is not unique (i.e. another task .. note:: If the specified ``taskName`` is not unique (i.e. another
with the same name may already be enqueued), the task with the same name may already be enqueued), the
:meth:`isQueued` method will probably return invalid :meth:`isQueued` method will probably return invalid
results. 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( log.debug('Enqueueing task: {} [{}]'.format(
name, getattr(func, '__name__', '<unknown>'))) name, getattr(func, '__name__', '<unknown>')))
...@@ -516,8 +528,6 @@ class TaskThread(threading.Thread): ...@@ -516,8 +528,6 @@ class TaskThread(threading.Thread):
log.debug('Task thread finished') log.debug('Task thread finished')
def mutex(*args, **kwargs): def mutex(*args, **kwargs):
"""Decorator for use on methods of a class, which makes the method """Decorator for use on methods of a class, which makes the method
call mutually exclusive. call mutually exclusive.
......
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