Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
75b5f8c1
Commit
75b5f8c1
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Adjustment to TaskThread.enqueue - now accepts task name/callback as
keyword arguments.
parent
eca48715
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fsl/data/imagewrapper.py
+2
-2
2 additions, 2 deletions
fsl/data/imagewrapper.py
fsl/utils/async.py
+19
-9
19 additions, 9 deletions
fsl/utils/async.py
with
21 additions
and
11 deletions
fsl/data/imagewrapper.py
+
2
−
2
View file @
75b5f8c1
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
fsl/utils/async.py
+
19
−
9
View file @
75b5f8c1
...
@@ -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 b
e passed through to the task when it is
All other arguments
ar
e passed through to the task
function
when it is
executed.
executed.
.. note:: If the specified ``
n
ame`` is not unique (i.e. another
task
.. note:: If the specified ``
taskN
ame`` 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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment