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
911e7134
Commit
911e7134
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
New async function idleWhen, which allows a condition function to
dictate when the actual function is called.
parent
e7095d0d
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/async.py
+24
-0
24 additions, 0 deletions
fsl/utils/async.py
with
24 additions
and
0 deletions
fsl/utils/async.py
+
24
−
0
View file @
911e7134
...
@@ -20,6 +20,7 @@ Idle tasks
...
@@ -20,6 +20,7 @@ Idle tasks
:nosignatures:
:nosignatures:
idle
idle
idleWhen
inIdle
inIdle
...
@@ -323,6 +324,29 @@ def idle(task, *args, **kwargs):
...
@@ -323,6 +324,29 @@ def idle(task, *args, **kwargs):
task
(
*
args
,
**
kwargs
)
task
(
*
args
,
**
kwargs
)
def
idleWhen
(
func
,
condition
,
*
args
,
**
kwargs
):
"""
Poll the ``condition`` function periodically, and schedule ``func`` on
:func:`idle` when it returns ``True``.
:arg func: Function to call.
:arg condition: Function which returns ``True`` or ``False``. The ``func``
function is only called when the ``condition`` function
returns ``True``.
:arg pollTime: Must be passed as a keyword argument. Time (in seconds) to
wait between successive calls to ``when``.
"""
pollTime
=
kwargs
.
get
(
'
pollTime
'
,
0.2
)
if
not
condition
():
idle
(
idleWhen
,
func
,
condition
,
after
=
pollTime
,
*
args
,
**
kwargs
)
else
:
kwargs
.
pop
(
'
pollTime
'
,
None
)
idle
(
func
,
*
args
,
**
kwargs
)
def
wait
(
threads
,
task
,
*
args
,
**
kwargs
):
def
wait
(
threads
,
task
,
*
args
,
**
kwargs
):
"""
Creates and starts a new ``Thread`` which waits for all of the ``Thread``
"""
Creates and starts a new ``Thread`` which waits for all of the ``Thread``
instances to finsih (by ``join``ing them), and then runs the given
instances to finsih (by ``join``ing them), and then runs the given
...
...
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