diff --git a/job_runner.py b/job_runner.py index 53bfcc7..4cef7c3 100644 --- a/job_runner.py +++ b/job_runner.py @@ -1,57 +1,56 @@ # -*- coding: utf-8 -*- from os import path, remove import shutil import subprocess class GridEngineJobRunner: def __init__(self, directory): self.directory = directory def _grid_jobname(self, job): return 'wd-shex-infer-%d' % job.id def run(self, job): with open(path.join(self.directory, '%d.entities.sparql' % job.id), 'w', encoding='utf-8') as entities_sparql: shutil.copyfileobj(job.input_sparql, entities_sparql) job.input_sparql.seek(0) subprocess.call( ['jsub', '-N', self._grid_jobname(job), '-mem', '8g', '-p', '-512', '-cwd', - '-v', 'PATH', + 'env', 'PATH=%s' % (path.expanduser('~/.local/bin') + ':' + path.defpath), 'make', '%d.shex' % job.id], - cwd=self.directory, - env={'PATH': path.expanduser('~/.local/bin') + ':' + path.defpath}) + cwd=self.directory) def get_output(self, job): returncode = subprocess.call( ['qstat', '-j', self._grid_jobname(job)]) if returncode == 0: return None # job is still running else: try: output_shex = open(path.join(self.directory, '%d.shex' % job.id), 'r', encoding='utf-8') except FileNotFoundError: output_shex = None output_stdout = open(path.expanduser('~/wd-shex-infer-%d.out' % job.id), 'r', encoding='utf-8') output_stderr = open(path.expanduser('~/wd-shex-infer-%d.err' % job.id), 'r', encoding='utf-8') return output_shex, output_stdout, output_stderr def clean(self, job): cleanups = [(remove, path.join(self.directory, '%d.entities.sparql' % job.id)), (remove, path.join(self.directory, '%d.nt' % job.id)), (shutil.rmtree, path.join(self.directory, '%d-fuseki' % job.id)), (shutil.rmtree, path.join(self.directory, '%d-results' % job.id)), (remove, path.join(self.directory, '%d.shex' % job.id)), (remove, path.expanduser('~/wd-shex-infer-%d.out' % job.id)), (remove, path.expanduser('~/wd-shex-infer-%d.err' % job.id))] for function, argument in cleanups: try: function(argument) except FileNotFoundError: pass