Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD 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
Evan Edmond
fslpy
Commits
9b90641b
Commit
9b90641b
authored
4 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ENH: TaskThread accepts an onError function which is called on idle loop if
queued task raises an error.
parent
16056e41
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/idle.py
+19
-6
19 additions, 6 deletions
fsl/utils/idle.py
with
19 additions
and
6 deletions
fsl/utils/idle.py
+
19
−
6
View file @
9b90641b
...
@@ -759,10 +759,11 @@ class Task(object):
...
@@ -759,10 +759,11 @@ class Task(object):
"""
Container object which encapsulates a task that is run by a
"""
Container object which encapsulates a task that is run by a
:class:`TaskThread`.
:class:`TaskThread`.
"""
"""
def
__init__
(
self
,
name
,
func
,
onFinish
,
args
,
kwargs
):
def
__init__
(
self
,
name
,
func
,
onFinish
,
onError
,
args
,
kwargs
):
self
.
name
=
name
self
.
name
=
name
self
.
func
=
func
self
.
func
=
func
self
.
onFinish
=
onFinish
self
.
onFinish
=
onFinish
self
.
onError
=
onError
self
.
args
=
args
self
.
args
=
args
self
.
kwargs
=
kwargs
self
.
kwargs
=
kwargs
self
.
enabled
=
True
self
.
enabled
=
True
...
@@ -808,9 +809,16 @@ class TaskThread(threading.Thread):
...
@@ -808,9 +809,16 @@ class TaskThread(threading.Thread):
: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. Must be provided as
when the task funtion has finished. Must be provided as
a keyword argument. If the ``func`` raises a
a keyword argument, and must itself accept no arguments.
:class`TaskThreadVeto` error, this function will not
If the ``func`` raises a :class`TaskThreadVeto` error,
be called.
this function will not be called.
:arg onError: An optional function to be called (via :func:`idle`)
if the task funtion raises an ``Exception``. Must be
provided as a keyword argument, and must itself accept
the raised ``Exception`` object as a single argument.
If the ``func`` raises a :class`TaskThreadVeto` error,
this function will not be called.
All other arguments are passed through to the task function when it is
All other arguments are passed through to the task function when it is
executed.
executed.
...
@@ -821,16 +829,18 @@ class TaskThread(threading.Thread):
...
@@ -821,16 +829,18 @@ class TaskThread(threading.Thread):
results.
results.
.. warning:: Make sure that your task function is not expecting keyword
.. warning:: Make sure that your task function is not expecting keyword
arguments called ``taskName`` or ``onFinish``!
arguments called ``taskName``, ``onFinish``, or
``onError``!
"""
"""
name
=
kwargs
.
pop
(
'
taskName
'
,
None
)
name
=
kwargs
.
pop
(
'
taskName
'
,
None
)
onFinish
=
kwargs
.
pop
(
'
onFinish
'
,
None
)
onFinish
=
kwargs
.
pop
(
'
onFinish
'
,
None
)
onError
=
kwargs
.
pop
(
'
onError
'
,
None
)
log
.
debug
(
'
Enqueueing task: {} [{}]
'
.
format
(
log
.
debug
(
'
Enqueueing task: {} [{}]
'
.
format
(
name
,
getattr
(
func
,
'
__name__
'
,
'
<unknown>
'
)))
name
,
getattr
(
func
,
'
__name__
'
,
'
<unknown>
'
)))
t
=
Task
(
name
,
func
,
onFinish
,
args
,
kwargs
)
t
=
Task
(
name
,
func
,
onFinish
,
onError
,
args
,
kwargs
)
self
.
__enqueued
[
name
]
=
t
self
.
__enqueued
[
name
]
=
t
self
.
__q
.
put
(
t
)
self
.
__q
.
put
(
t
)
...
@@ -951,6 +961,9 @@ class TaskThread(threading.Thread):
...
@@ -951,6 +961,9 @@ class TaskThread(threading.Thread):
type
(
e
).
__name__
,
type
(
e
).
__name__
,
str
(
e
)),
str
(
e
)),
exc_info
=
True
)
exc_info
=
True
)
if
task
.
onError
is
not
None
:
idle
(
task
.
onError
,
e
)
finally
:
finally
:
self
.
__q
.
task_done
()
self
.
__q
.
task_done
()
...
...
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