From 4b7a46b640d9607f5cac919d5aa3e89761a68df8 Mon Sep 17 00:00:00 2001 From: "Christoph.Knote" <christoph.knote@physik.uni-muenchen.de> Date: Thu, 14 Dec 2017 07:35:29 +0100 Subject: [PATCH] OK, it won't work, probably, but it's a first try. --- boxmox/experiment.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/boxmox/experiment.py b/boxmox/experiment.py index 63bd708..8d65d59 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 = {} -- GitLab