Skip to content
Snippets Groups Projects
Commit 24dd7e4d authored by Christoph.Knote's avatar Christoph.Knote
Browse files

More crazy shit.

parent 5040d715
Branches
Tags
No related merge requests found
...@@ -4,6 +4,7 @@ if os.name == 'posix' and sys.version_info[0] < 3: ...@@ -4,6 +4,7 @@ if os.name == 'posix' and sys.version_info[0] < 3:
import subprocess32 as s import subprocess32 as s
else: else:
import subprocess as s import subprocess as s
import threading
import shutil import shutil
import fnmatch import fnmatch
import numpy as np import numpy as np
...@@ -186,6 +187,27 @@ class Experiment: ...@@ -186,6 +187,27 @@ class Experiment:
return mech return mech
@property
def running(self):
'''
Check if simulation is running (if started with asynchronous=True).
'''
if self.pid is None:
return False
else:
return self.pid.poll() is None
def _run(self, dumbOutput=False):
try:
self.pid = s.Popen("./" + self.mechanism + ".exe", stdout=s.PIPE, bufsize=1)
self.pid.wait()
self._pp_run(dumbOutput=dumbOutput)
except Exception as e:
failDir = self.path + "_failed_at_{:s}".format(datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d%H%M%S"))
self.archive( failDir )
raise Exception('BOXMOX integration failed: {:s}'.format(str(e)))
return
def run(self, dumbOutput=False, asynchronous=False): def run(self, dumbOutput=False, asynchronous=False):
''' '''
Run BOXMOX experiment Run BOXMOX experiment
...@@ -202,29 +224,28 @@ class Experiment: ...@@ -202,29 +224,28 @@ class Experiment:
pwd = os.getcwd() pwd = os.getcwd()
os.chdir(self.path) os.chdir(self.path)
try: if asynchronous:
self.pid = s.Popen("./" + self.mechanism + ".exe", stdout=s.PIPE, bufsize=1) thread = threading.Thread(target=self._run, args=(dumbOutput,))
if asynchronous: thread.start()
return os.chdir(pwd)
self.pid.wait() # wait for the subprocess to exit return
else:
self._run(dumbOutput=dumbOutput)
os.chdir(pwd)
def _pp_run(self, dumbOutput=False):
try:
self.lastLog = [] self.lastLog = []
for line in iter(self.pid.stdout.readline, b''): for line in iter(self.pid.stdout.readline, b''):
self.lastLog.append(line.replace('\n','')) self.lastLog.append(line.replace('\n',''))
except:
except Exception as e: pass
os.chdir(pwd)
failDir = self.path + "_failed_at_{:s}".format(datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d%H%M%S"))
self.archive( failDir )
raise Exception('BOXMOX integration failed: {:s}'.format(str(e)))
if dumbOutput: if dumbOutput:
self._populateDumbOutput() self._populateDumbOutput()
else: else:
self._populateOutput() self._populateOutput()
os.chdir(pwd)
outputTypes = { 'Concentrations': { 'ending': '.conc', 'class': ConcentrationOutput }, outputTypes = { 'Concentrations': { 'ending': '.conc', 'class': ConcentrationOutput },
'Rates': { 'ending': '.rates', 'class': RatesOutput }, 'Rates': { 'ending': '.rates', 'class': RatesOutput },
'Jacobian': { 'ending': '.jacobian', 'class': JacobianOutput }, 'Jacobian': { 'ending': '.jacobian', 'class': JacobianOutput },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment