From 2dc2941290afa8acdf82d37f1828110e2d257b61 Mon Sep 17 00:00:00 2001 From: Cezary Czaplewski Date: Tue, 22 Aug 2017 09:46:44 +0200 Subject: [PATCH] changes of os.chdir(instance.jobdirname) os.chdir('..') error should not propagate to the next job --- django_simple/todo/jobfiles.py | 21 ++++++++++++++------- django_simple/todo/views.py | 3 ++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/django_simple/todo/jobfiles.py b/django_simple/todo/jobfiles.py index 69c809e..048e030 100644 --- a/django_simple/todo/jobfiles.py +++ b/django_simple/todo/jobfiles.py @@ -32,7 +32,7 @@ def write_on_task_save(sender, instance, **kwargs): if instance.ready and not instance.done and instance.running==0: if (not os.path.isdir(instance.jobdirname)): os.mkdir(instance.jobdirname) - os.chdir(instance.jobdirname) +# os.chdir(instance.jobdirname) @@ -48,7 +48,7 @@ WVDWPP=0.23173 WHPB=1.00000 WSCCOR=0.25 & CUTOFF=7.00000 WCORR4=0.00000 """ - with open('file.inp','w') as f: + with open(instance.jobdirname+'/file.inp','w') as f: f.write(instance.name + ' UNRES server job'+ '\n') if instance.type == 'min' : @@ -205,9 +205,12 @@ CUTOFF=7.00000 WCORR4=0.00000 if instance.type == 'min': + os.chdir(instance.jobdirname) shutil.copy('../files/pbs.csh','.') ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + os.chdir('..') elif instance.type == 'md': + os.chdir(instance.jobdirname) f1 = open('../files/pbs_md.csh', 'r') f2 = open('pbs.csh', 'w') for line in f1: @@ -221,6 +224,7 @@ CUTOFF=7.00000 WCORR4=0.00000 f1.close() ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + os.chdir('..') else: tmp1=json.loads(instance.remd_multi_m) nreplicas=sum(map(int, tmp1)) @@ -233,6 +237,7 @@ CUTOFF=7.00000 WCORR4=0.00000 else: pbs = '#PBS -l nodes='+str(nodes)+':ppn=4+1:ppn='+str(reszta) + os.chdir(instance.jobdirname) f1 = open('../files/pbs8.csh', 'r') f2 = open('pbs8.csh', 'w') for line in f1: @@ -242,10 +247,11 @@ CUTOFF=7.00000 WCORR4=0.00000 tmp1=json.loads(instance.remd_multi_t) f2.write(line.replace('$temperatures','"'+" ".join(tmp1)+'"')) f1.close() - f2.close() + f2.close() + os.chdir('..') # write wham & cluster input - with open('file_wham.inp','w') as f: + with open(instance.jobdirname+'/file_wham.inp','w') as f: if instance.md_nstep/instance.remd_nstex*nreplicas<=8000: isampl=1 else: @@ -280,7 +286,7 @@ CUTOFF=7.00000 WCORR4=0.00000 f.write('plik.pdb\n') - with open('file_cluster.inp','w') as f: + with open(instance.jobdirname+'/file_cluster.inp','w') as f: f.write(instance.name + ' UNRES server job'+ '\n') f.write('nres='+str(len(seq)) +' one_letter rescale=2 PRINT_CART PDBOUT=1 iopt=1' @@ -289,11 +295,12 @@ CUTOFF=7.00000 WCORR4=0.00000 for i in range(0,len(seq),80): f.write(seq[i:i+80]+'\n') f.write(write_ssbond(instance.ssbond)) - + + os.chdir(instance.jobdirname) ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs8.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + os.chdir('..') print ret_code.stdout.readlines() - os.chdir('..') logger.warning("Dir \"%s\" has been saved." % instance.jobdirname) @receiver(post_delete, sender=Task) diff --git a/django_simple/todo/views.py b/django_simple/todo/views.py index 2134ae5..899f08b 100644 --- a/django_simple/todo/views.py +++ b/django_simple/todo/views.py @@ -425,9 +425,10 @@ def refresh_done(request): task.running =1 else: with open(task.jobdirname+'/file_GB000.stat', 'r') as f: + line='' for line in f: pass - if line: + if line != '': last = line.split()[0] else: last = 0 -- 1.7.9.5