44import subprocess
55import threading
66import copy
7+ import time , datetime
78
89__DIFFLIB__ = False
910try :
@@ -235,6 +236,7 @@ def __init__(self, hostname=None, pwd=None, extra_options="", workdir = "",
235236 self .additional_script_parameters = None
236237
237238
239+
238240 # Allow to setup additional custom extra parameters
239241 self .custom_params = {}
240242
@@ -550,7 +552,7 @@ def submit(self, script_location):
550552
551553 .. code ::
552554
553- return self.ExecuteCMD(cmd, False )
555+ return self.ExecuteCMD(cmd, True, return_output=True )
554556
555557
556558
@@ -576,9 +578,8 @@ def submit(self, script_location):
576578
577579 #cmd = self.sshcmd + " %s '%s %s/%s.sh'" % (self.hostname, self.submit_command,
578580 # self.workdir, label+ "_" + str(indices[0]))
579- cp_res = self .ExecuteCMD (cmd , False )
580- return cp_res
581-
581+
582+ return self .ExecuteCMD (cmd , True , return_output = True )
582583
583584 def batch_submission (self , list_of_structures , calc , indices ,
584585 in_extension , out_extension ,
@@ -679,14 +680,19 @@ def batch_submission(self, list_of_structures, calc, indices,
679680
680681 # Run the simulation
681682 sub_script_loc = os .path .join (self .workdir , label + "_" + str (indices [0 ]) + ".sh" )
682- cp_res = self .submit (sub_script_loc )
683+ cp_res , submission_output = self .submit (sub_script_loc )
683684
684- # cp_res = os.system(cmd + " > /dev/null")
685- # if cp_res != 0:
686- # print "Error while executing:", cmd
687- # print "Return code:", cp_res
688- # sys.stderr.write(cmd + ": exit with code " + str(cp_res))
689- #
685+ if self .nonblocking_command :
686+ job_id = self .get_job_id_from_submission_output (submission_output )
687+
688+ now = datetime .datetime .now ()
689+ sys .stderr .write ("{}/{}/{} - {}:{} | submitted job id {} ({})\n " .format (now .year , now .month , now .day , now .hour , now .minute , now .second , job_id , submission_output ))
690+ sys .stderr .flush ()
691+ time .sleep (self .check_timeout )
692+
693+ while not self .check_job_finished (job_id ):
694+ time .sleep (self .check_timeout )
695+
690696
691697 # Collect the output back
692698 for i in submitted :
0 commit comments