Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pytools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
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
Andreas Klöckner
pytools
Commits
9874ec11
Commit
9874ec11
authored
17 years ago
by
Andreas Klöckner
Browse files
Options
Downloads
Patches
Plain Diff
Add batch job submission tools.
parent
404ba014
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
src/batchjob.py
+116
-0
116 additions, 0 deletions
src/batchjob.py
with
116 additions
and
0 deletions
src/batchjob.py
0 → 100644
+
116
−
0
View file @
9874ec11
from
__future__
import
with_statement
def
_cp
(
src
,
dest
):
from
pytools
import
assert_not_a_file
assert_not_a_file
(
dest
)
with
open
(
src
,
"
rb
"
)
as
inf
:
with
open
(
dest
,
"
wb
"
)
as
outf
:
outf
.
write
(
inf
.
read
())
class
BatchJob
(
object
):
def
__init__
(
self
,
moniker
,
main_file
,
aux_files
=
[]):
from
datetime
import
datetime
import
os
import
os.path
self
.
moniker
=
moniker
self
.
subdir
=
os
.
path
.
join
(
os
.
getcwd
(),
"
%s-%s
"
%
(
moniker
,
datetime
.
now
().
strftime
(
"
%Y-%m-%d-%H%M%S
"
)))
os
.
mkdir
(
self
.
subdir
)
with
open
(
"
%s/run.sh
"
%
self
.
subdir
,
"
w
"
)
as
runscript
:
import
sys
runscript
.
write
(
"
%s %s setup.cpy
"
%
(
sys
.
executable
,
main_file
))
_cp
(
main_file
,
os
.
path
.
join
(
self
.
subdir
,
main_file
))
for
aux_file
in
aux_files
:
_cp
(
aux_file
,
os
.
path
.
join
(
self
.
subdir
,
aux_file
))
def
write_setup
(
self
,
lines
):
import
os.path
with
open
(
os
.
path
.
join
(
self
.
subdir
,
"
setup.cpy
"
),
"
w
"
)
as
setup
:
setup
.
write
(
"
\n
"
.
join
(
lines
))
class
INHERIT
(
object
):
pass
class
GridEngineJob
(
BatchJob
):
def
submit
(
self
,
env
=
{
"
LD_LIBRARY_PATH
"
:
INHERIT
,
"
PYTHONPATH
"
:
INHERIT
}):
from
subprocess
import
Popen
args
=
[
"
-N
"
,
self
.
moniker
,
"
-cwd
"
,
]
from
os
import
getenv
for
var
,
value
in
env
.
iteritems
():
if
value
is
INHERIT
:
value
=
getenv
(
var
)
args
+=
[
"
-v
"
,
"
%s=%s
"
%
(
var
,
value
)]
subproc
=
Popen
([
"
qsub
"
]
+
args
+
[
"
run.sh
"
],
cwd
=
self
.
subdir
)
if
subproc
.
wait
()
!=
0
:
raise
RuntimeError
(
"
Process submission of %s failed
"
%
self
.
moniker
)
class
PBSJob
(
BatchJob
):
def
submit
(
self
,
env
=
{
"
LD_LIBRARY_PATH
"
:
INHERIT
,
"
PYTHONPATH
"
:
INHERIT
}):
from
subprocess
import
Popen
args
=
[
"
-N
"
,
self
.
moniker
,
]
from
os
import
getenv
for
var
,
value
in
env
.
iteritems
():
if
value
is
INHERIT
:
value
=
getenv
(
var
)
args
+=
[
"
-v
"
,
"
%s=%s
"
%
(
var
,
value
)]
subproc
=
Popen
([
"
qsub
"
]
+
args
+
[
"
run.sh
"
],
cwd
=
self
.
subdir
)
if
subproc
.
wait
()
!=
0
:
raise
RuntimeError
(
"
Process submission of %s failed
"
%
self
.
moniker
)
class
ConstructorPlaceholder
:
def
__init__
(
self
,
classname
,
*
args
,
**
kwargs
):
self
.
classname
=
classname
self
.
args
=
args
self
.
kwargs
=
kwargs
def
arg
(
self
,
i
):
return
self
.
args
[
i
]
def
kwarg
(
self
,
name
):
return
self
.
kwargs
[
name
]
def
__str__
(
self
):
return
"
%s(%s)
"
%
(
self
.
classname
,
"
,
"
.
join
(
[
str
(
arg
)
for
arg
in
self
.
args
]
+
[
"
%s=%s
"
%
(
kw
,
val
)
for
kw
,
val
in
self
.
kwargs
.
iteritems
()]
)
)
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