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

More crazy shit.

parent 5040d715
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ if os.name == 'posix' and sys.version_info[0] < 3:
import subprocess32 as s
else:
import subprocess as s
import threading
import shutil
import fnmatch
import numpy as np
......@@ -186,6 +187,27 @@ class Experiment:
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):
'''
Run BOXMOX experiment
......@@ -202,29 +224,28 @@ class Experiment:
pwd = os.getcwd()
os.chdir(self.path)
try:
self.pid = s.Popen("./" + self.mechanism + ".exe", stdout=s.PIPE, bufsize=1)
if asynchronous:
return
self.pid.wait() # wait for the subprocess to exit
if asynchronous:
thread = threading.Thread(target=self._run, args=(dumbOutput,))
thread.start()
os.chdir(pwd)
return
else:
self._run(dumbOutput=dumbOutput)
os.chdir(pwd)
def _pp_run(self, dumbOutput=False):
try:
self.lastLog = []
for line in iter(self.pid.stdout.readline, b''):
self.lastLog.append(line.replace('\n',''))
except Exception as e:
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)))
except:
pass
if dumbOutput:
self._populateDumbOutput()
else:
self._populateOutput()
os.chdir(pwd)
outputTypes = { 'Concentrations': { 'ending': '.conc', 'class': ConcentrationOutput },
'Rates': { 'ending': '.rates', 'class': RatesOutput },
'Jacobian': { 'ending': '.jacobian', 'class': JacobianOutput },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment