So I have created a logger which logs to both file and console. However, I need to call subprocess to run other python files but the problem is that console and file is only populated with logging messages once the subprocess has complete even though I have implemented logging within the python files. I would like it to log to console during a subprocess. That is, I am able to see output during the running on the other files.
Any ideas? or is there another way to run a python file within python?
My subprocess function:
def _run_cmd(args_list):
"""
run linux commands
"""
# import subprocess
print('Running system command: {0}'.format(' '.join(args_list)))
proc = subprocess.Popen(args_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
s_output, s_err = proc.communicate()
s_return = proc.returncode
return s_return, s_output, s_err
Where I call the subprocess:
try:
s_return, s_output, s_err = _run_cmd(["python", abs_path])
if s_err:
finish_fail(config, logger)
except Exception as e:
logger.error("error", str(e))
abs_path
is the location to the file which I would like to run.