import subprocess as subproc import os from mubench import CALLBACKS_DIR from mubench.lang import Language from mubench.exceptions import ExecutionFailure from mubench.util import expandenv class Python(Language): name = 'python' src_ext = 'py' compiled = False default_exec = 'python' @classmethod def check_runner(cls, rc, lc, env): # python interpreter python = rc.get('exec', cls.default_exec) rc['exec'] = expandenv(python, env) # PYTHOPATH pythonpath = env.get('PYTHONPATH', '') callback_dir = CALLBACKS_DIR / 'python' pythonpath = '%(callback_dir)s:%(pythonpath)s' % locals() env['PYTHONPATH'] = pythonpath return rc @classmethod def run(cls, target, task): rc = task.runner_conf bmc = task.benchmark_conf cmd = [] cmd.append(rc['exec']) cmd.append(target) # first & second argument: callback class name and parameter string cmd.append(task.callback_conf['name']) cmd.append(task.callback_conf['param']) # third argument: iterations cmd.append(bmc['iterations']) cmd.extend(bmc['args']) # place callback module on PYTHONPATH env = os.environ.copy() pythonpath = env.get('PYTHONPATH', '') callback_dir = CALLBACKS_DIR / 'python' pythonpath = '%(callback_dir)s:%(pythonpath)s' % locals() env['PYTHONPATH'] = pythonpath return cls.run_in_subproc(cmd, os.environ)