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
54879a1f
Commit
54879a1f
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ENH: idle.block now accepts a conditional function which can control how long
it blocks for
parent
cab37727
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
+23
-9
23 additions, 9 deletions
fsl/utils/idle.py
with
23 additions
and
9 deletions
fsl/utils/idle.py
+
23
−
9
View file @
54879a1f
...
...
@@ -391,27 +391,41 @@ def cancelIdle(taskName):
_idleQueueDict
[
taskName
].
timeout
=
-
1
def
block
(
secs
,
delta
=
0.01
):
def
block
(
secs
,
delta
=
0.01
,
until
=
None
):
"""
Blocks for the specified number of seconds, yielding to the main ``wx``
loop.
If ``wx`` is not available, or a ``wx`` application is not running, this
function is equivalent to ``time.sleep(secs)``.
If ``until`` is provided, this function will block until ``until``
returns ``True``, or ``secs`` have elapsed, whichever comes first.
:arg secs: Time in seconds to block
:arg delta: Time in seconds to sleep between successive yields to ``wx``.
:arg until: Function which returns ``True`` or ``False``, and which
determins when calls to ``block`` will return.
"""
from
fsl.utils.platform
import
platform
as
fslplatform
def
defaultUntil
():
return
False
if
not
fslplatform
.
haveGui
:
time
.
sleep
(
secs
)
else
:
import
wx
start
=
time
.
time
()
while
(
time
.
time
()
-
start
)
<
secs
:
def
tick
():
if
fslplatform
.
haveGui
:
import
wx
wx
.
YieldIfNeeded
()
time
.
sleep
(
delta
)
time
.
sleep
(
delta
)
if
until
is
None
:
until
=
defaultUntil
from
fsl.utils.platform
import
platform
as
fslplatform
start
=
time
.
time
()
while
(
time
.
time
()
-
start
)
<
secs
:
tick
()
if
until
():
break
def
idle
(
task
,
*
args
,
**
kwargs
):
...
...
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