Skip to content

Commit

Permalink
Merge pull request #82 from njzjz/shell
Browse files Browse the repository at this point in the history
fix shell
  • Loading branch information
njzjz committed Jul 4, 2021
2 parents 60f5c90 + 30c8aaf commit bd83853
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions dpdispatcher/shell.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import psutil
#import psutil

from dpdispatcher.JobStatus import JobStatus
from dpdispatcher import dlog
Expand All @@ -22,10 +22,12 @@ def do_submit(self, job):
script_file_name = job.script_file_name
job_id_name = job.job_hash + '_job_id'
self.context.write_file(fname=script_file_name, write_str=script_str)
proc = self.context.call('cd %s && exec bash %s &' % (self.context.remote_root, script_file_name) )
proc.wait()
# proc.kill()
job_id = int(proc.pid)
ret, stdin, stdout, stderr = self.context.block_call('cd %s && echo $$ && exec bash %s &' % (self.context.remote_root, script_file_name) )
if ret != 0:
err_str = stderr.read().decode('utf-8')
raise RuntimeError\
("status command squeue fails to execute\nerror message:%s\nreturn code %d\n" % (err_str, ret))
job_id = int(stdout.read().decode('utf-8').strip())
self.context.write_file(job_id_name, str(job_id))
return job_id

Expand All @@ -51,7 +53,13 @@ def check_status(self, job):
if job_id == "" :
return JobStatus.unsubmitted

if_job_exists = psutil.pid_exists(pid=job_id)
ret, stdin, stdout, stderr = self.context.block_call(f"if ps -p {job_id} > /dev/null; then echo 1; fi")
if ret != 0:
err_str = stderr.read().decode('utf-8')
raise RuntimeError\
("status command squeue fails to execute\nerror message:%s\nreturn code %d\n" % (err_str, ret))

if_job_exists = bool(stdout.read().decode('utf-8').strip())
if self.check_finish_tag(job=job):
dlog.info(f"job: {job.job_hash} {job.job_id} finished")
return JobStatus.finished
Expand Down

0 comments on commit bd83853

Please sign in to comment.