Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
wtlib
WindEnergyToolbox
Commits
97a9b23c
Commit
97a9b23c
authored
9 years ago
by
mads
Browse files
Options
Downloads
Patches
Plain Diff
added pbsjob.py
parent
56601e0f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
wetb/utils/cluster_tools/__init__.py
+0
-0
0 additions, 0 deletions
wetb/utils/cluster_tools/__init__.py
wetb/utils/cluster_tools/pbsjob.py
+89
-0
89 additions, 0 deletions
wetb/utils/cluster_tools/pbsjob.py
with
89 additions
and
0 deletions
wetb/utils/cluster_tools/__init__.py
0 → 100644
+
0
−
0
View file @
97a9b23c
This diff is collapsed.
Click to expand it.
wetb/utils/cluster_tools/pbsjob.py
0 → 100644
+
89
−
0
View file @
97a9b23c
'''
Created on 04/12/2015
@author: mmpe
'''
#import x
import
time
from
wetb.utils.cluster_tools.ssh_client
import
SSHClient
import
os
import
paramiko
import
subprocess
NOT_SUBMITTED
=
"
Job not submitted
"
PENDING
=
"
Pending
"
RUNNING
=
"
Running
"
DONE
=
"
Done
"
class
PBSJob
(
object
):
_status
=
NOT_SUBMITTED
nodeid
=
None
def
__init__
(
self
,
host
,
username
,
password
):
self
.
client
=
SSHClient
(
host
,
username
,
password
,
port
=
22
)
def
execute
(
self
,
cmd
,
cwd
=
"
./
"
):
proc
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
shell
=
True
,
cwd
=
cwd
)
stdout
,
stderr
=
proc
.
communicate
()
errorcode
=
proc
.
returncode
return
errorcode
,
stdout
.
decode
(),
stderr
.
decode
()
def
submit
(
self
,
job
,
cwd
,
pbs_out_file
):
self
.
cwd
=
cwd
self
.
pbs_out_file
=
os
.
path
.
relpath
(
cwd
+
pbs_out_file
).
replace
(
"
\\
"
,
"
/
"
)
self
.
nodeid
=
None
try
:
os
.
remove
(
self
.
pbs_out_file
)
except
FileNotFoundError
:
pass
_
,
out
,
_
=
self
.
execute
(
"
qsub %s
"
%
job
,
cwd
)
self
.
jobid
=
out
.
split
(
"
.
"
)[
0
]
self
.
_status
=
PENDING
@property
def
status
(
self
):
if
self
.
_status
in
[
NOT_SUBMITTED
,
DONE
]:
return
self
.
_status
if
self
.
nodeid
is
None
:
self
.
nodeid
=
self
.
get_nodeid
()
if
self
.
nodeid
is
not
None
:
self
.
_status
=
RUNNING
if
self
.
in_queue
()
and
self
.
nodeid
is
None
:
self
.
_status
=
PENDING
elif
os
.
path
.
isfile
(
self
.
pbs_out_file
):
self
.
_status
=
DONE
return
self
.
_status
def
get_nodeid
(
self
):
errorcode
,
out
,
err
=
self
.
execute
(
"
qstat -f %s | grep exec_host
"
%
self
.
jobid
)
if
errorcode
==
0
:
return
out
.
strip
().
replace
(
"
exec_host =
"
,
""
).
split
(
"
.
"
)[
0
]
elif
errorcode
==
1
and
out
==
""
:
return
None
elif
errorcode
==
153
and
'
qstat: Unknown Job Id
'
in
err
:
return
None
else
:
raise
Exception
(
str
(
errorcode
)
+
out
+
err
)
def
stop
(
self
):
try
:
self
.
execute
(
"
qdel %s
"
%
self
.
jobid
)
except
Warning
as
e
:
if
'
qdel: Unknown Job Id
'
in
str
(
e
):
return
raise
e
def
in_queue
(
self
):
errorcode
,
out
,
err
=
self
.
execute
(
"
qstat %s
"
%
self
.
jobid
)
if
errorcode
==
0
:
return
True
elif
'
qstat: Unknown Job Id
'
in
str
(
err
):
return
False
else
:
raise
Exception
(
str
(
errorcode
)
+
out
+
err
)
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