diff --git a/boxmox/experiment.py b/boxmox/experiment.py index 63bd708d324164478b2bc36fab536a204047270e..8d65d5927e31b151263bed09d847759f69250a9a 100644 --- a/boxmox/experiment.py +++ b/boxmox/experiment.py @@ -112,6 +112,8 @@ class Experiment: #: Log file of the last run self.lastLog = None + self.pid = None + self.__new() #: Namelist @@ -184,11 +186,12 @@ class Experiment: return mech - def run(self, dumbOutput=False): + def run(self, dumbOutput=False, asynchronous=False): ''' Run BOXMOX experiment :param bool dumbOutput: Only load references to output files, instead of loading data? (faster, but not usable for analysis) + :param bool asynchronous: Run asynchronous? ''' self.namelist.write(os.path.join(self.path, 'BOXMOX.nml')) @@ -200,11 +203,13 @@ class Experiment: os.chdir(self.path) try: - p = s.Popen("./" + self.mechanism + ".exe", stdout=s.PIPE, bufsize=1) - p.wait() # wait for the subprocess to exit + self.pid = s.Popen("./" + self.mechanism + ".exe", stdout=s.PIPE, bufsize=1) + if asynchronous: + return + self.pid.wait() # wait for the subprocess to exit self.lastLog = [] - for line in iter(p.stdout.readline, b''): + for line in iter(self.pid.stdout.readline, b''): self.lastLog.append(line.replace('\n','')) except Exception as e: @@ -293,6 +298,8 @@ class ExperimentFromExample(Experiment): self.lastLog = None + self.pid = None + self.input = {} self.output = {} @@ -333,6 +340,8 @@ class ExperimentFromExistingRun(Experiment): self.lastLog = None + self.pid = None + self.input = {} self.output = {}