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
db9a3e6d
Commit
db9a3e6d
authored
4 years ago
by
Michiel Cottaar
Browse files
Options
Downloads
Patches
Plain Diff
ENH: new hold function
parent
1a506448
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/fslsub.py
+32
-0
32 additions, 0 deletions
fsl/utils/fslsub.py
with
32 additions
and
0 deletions
fsl/utils/fslsub.py
+
32
−
0
View file @
db9a3e6d
...
...
@@ -49,6 +49,7 @@ from dataclasses import dataclass, asdict
from
typing
import
Optional
,
Collection
,
Union
,
Tuple
,
Dict
import
argparse
import
warnings
import
os
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -402,6 +403,37 @@ def _flatten_job_ids(job_ids):
return
'
,
'
.
join
(
sorted
(
unpack
(
job_ids
)))
def
hold
(
job_ids
,
hold_filename
=
None
):
"""
Waits until all jobs have finished
Internally works by submitting a new job, which creates a file named `hold_filename`,
which will only run after all jobs in `job_ids` finished.
This function will only return once `hold_filename` has been created
:param job_ids: possibly nested sequence of job ids. The job ids themselves should be strings.
:param hold_filename: filename to use as a hold file.
The containing directory should exist, but the file itself should not.
Defaults to a ./.<random characters>.hold in the current directory.
:return: only returns when all the jobs have finished
"""
if
hold_filename
is
None
:
with
tempfile
.
NamedTemporaryFile
(
prefix
=
'
.
'
,
suffix
=
'
.hold
'
,
dir
=
'
.
'
)
as
f
:
hold_filename
=
f
.
name
if
op
.
exists
(
hold_filename
):
raise
IOError
(
f
"
Hold file (
{
hold_filename
}
) already exists
"
)
elif
not
op
.
isdir
(
op
.
split
(
op
.
abspath
(
hold_filename
))[
0
]):
raise
IOError
(
f
"
Hold file (
{
hold_filename
}
) can not be created in non-existent directory
"
)
submit
(
f
'
touch
{
hold_filename
}
'
,
wait_for
=
job_ids
,
minutes
=
1
,
job_name
=
'
.hold
'
)
while
not
op
.
exists
(
hold_filename
):
time
.
sleep
(
10
)
os
.
remove
(
hold_filename
)
_external_job
=
"""
#!{}
# This is a temporary file designed to run the python function {},
# so that it can be submitted to the cluster
...
...
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