mirror of https://github.com/VLSIDA/OpenRAM.git
Rework run_script command.
* Use Python subprocess module. * Echo the command output to the console. * Print while things are still running.
This commit is contained in:
parent
fa5296e621
commit
59c6980052
|
|
@ -11,24 +11,67 @@ Some baseline functions to run scripts.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import debug
|
import debug
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
from globals import OPTS
|
from globals import OPTS
|
||||||
|
|
||||||
|
|
||||||
def run_script(cell_name, script="lvs"):
|
def run_script(cell_name, script="lvs"):
|
||||||
""" Run script and create output files. """
|
""" Run script and create output files. """
|
||||||
|
|
||||||
|
# FIXME: Set this value based on options somewhere
|
||||||
|
echo_cmd_output = True
|
||||||
|
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
os.chdir(OPTS.openram_temp)
|
os.chdir(OPTS.openram_temp)
|
||||||
errfile = "{0}{1}.{2}.err".format(OPTS.openram_temp, cell_name, script)
|
errfile = "{0}{1}.{2}.err".format(OPTS.openram_temp, cell_name, script)
|
||||||
outfile = "{0}{1}.{2}.out".format(OPTS.openram_temp, cell_name, script)
|
outfile = "{0}{1}.{2}.out".format(OPTS.openram_temp, cell_name, script)
|
||||||
resultsfile = "{0}{1}.{2}.report".format(OPTS.openram_temp, cell_name, script)
|
resultsfile = "{0}{1}.{2}.report".format(OPTS.openram_temp, cell_name, script)
|
||||||
|
|
||||||
cmd = "{0}run_{1}.sh 2> {2} 1> {3}".format(OPTS.openram_temp,
|
scriptpath = '{0}run_{1}.sh'.format(OPTS.openram_temp, script)
|
||||||
script,
|
|
||||||
errfile,
|
debug.info(2, "Starting {}".format(scriptpath))
|
||||||
outfile)
|
start = time.time()
|
||||||
debug.info(2, cmd)
|
with open(outfile, 'wb') as fo, open(errfile, 'wb') as fe:
|
||||||
os.system(cmd)
|
p = subprocess.Popen(
|
||||||
|
[scriptpath], stdout=fo, stderr=fe, cwd=OPTS.openram_temp)
|
||||||
|
|
||||||
|
if echo_cmd_output:
|
||||||
|
tailo = subprocess.Popen([
|
||||||
|
'tail',
|
||||||
|
'-f', # Follow the output
|
||||||
|
'--pid', str(p.pid), # Close when this pid exits
|
||||||
|
outfile,
|
||||||
|
])
|
||||||
|
taile = subprocess.Popen([
|
||||||
|
'tail',
|
||||||
|
'-f', # Follow the output
|
||||||
|
'--pid', str(p.pid), # Close when this pid exits
|
||||||
|
errfile,
|
||||||
|
])
|
||||||
|
|
||||||
|
lastoutput = start
|
||||||
|
while p.poll() == None:
|
||||||
|
runningfor = time.time() - start
|
||||||
|
outputdelta = time.time() - lastoutput
|
||||||
|
if outputdelta > 30:
|
||||||
|
lastoutput = time.time()
|
||||||
|
debug.info(1, "Still running {} ({:.0f} seconds)".format(scriptpath, runningfor))
|
||||||
|
time.sleep(1)
|
||||||
|
assert p.poll() != None, (p.poll(), p)
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
# Kill the tail commands if they haven't finished.
|
||||||
|
if cmd_output:
|
||||||
|
if tailo.poll() != None:
|
||||||
|
tailo.kill()
|
||||||
|
tailo.wait()
|
||||||
|
if taile.poll() != None:
|
||||||
|
taile.kill()
|
||||||
|
taile.wait()
|
||||||
|
|
||||||
|
debug.info(2, "Finished {} with {}".format(scriptpath, p.returncode))
|
||||||
|
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
|
|
||||||
return (outfile, errfile, resultsfile)
|
return (outfile, errfile, resultsfile)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue