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
Model registry
Operate
Environments
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
FSL
fslpy
Commits
e7095d0d
Commit
e7095d0d
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TaskThread tasks can 'veto' the onFinish handler.
parent
75b5f8c1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/async.py
+19
-1
19 additions, 1 deletion
fsl/utils/async.py
with
19 additions
and
1 deletion
fsl/utils/async.py
+
19
−
1
View file @
e7095d0d
...
...
@@ -390,6 +390,15 @@ class Task(object):
self
.
enabled
=
True
class
TaskThreadVeto
(
Exception
):
"""
Task functions which are added to a :class:`TaskThread` may raise
a ``TaskThreadVeto`` error to skip processing of the task
'
s ``onFinish``
handler (if one has been specified). See the :meth:`TaskThread.enqueue`
method for more details.
"""
pass
class
TaskThread
(
threading
.
Thread
):
"""
The ``TaskThread`` is a simple thread which runs tasks. Tasks may be
enqueued and dequeued.
...
...
@@ -423,7 +432,9 @@ class TaskThread(threading.Thread):
:arg onFinish: An optional function to be called (via :func:`idle`)
when the task funtion has finished. Must be provided as
a keyword argument.
a keyword 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
executed.
...
...
@@ -514,6 +525,13 @@ class TaskThread(threading.Thread):
log
.
debug
(
'
Task completed: {} [{}]
'
.
format
(
task
.
name
,
getattr
(
task
.
func
,
'
__name__
'
,
'
<unknown>
'
)))
# If the task raises a TaskThreadVeto error,
# we just have to skip the onFinish handler
except
TaskThreadVeto
:
log
.
debug
(
'
Task completed (vetoed onFinish): {} [{}]
'
.
format
(
task
.
name
,
getattr
(
task
.
func
,
'
__name__
'
,
'
<unknown>
'
)))
except
Exception
as
e
:
log
.
debug
(
'
Task crashed: {} [{}]: {}: {}
'
.
format
(
...
...
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