我在Python 3函数中具有以下代码块
try:
score_string = subprocess.check_output([sys.executable, "-m", "query",
lab,
data_frame_path,
prior_model_path,
channel], stderr=subprocess.PIPE).decode('utf-8')
except subprocess.CalledProcessError as e:
out_bytes = e.output # Output generated before error
err_bytes = e.stderr
code = e.returncode # Return code
if log:
log.error("Invocation of train_model on %s %s %s failed with error %d." %
(lab, data_frame_path, prior_model_path, code))
log.error("Error output is:")
log.error(out_bytes.decode('utf-8'))
if err_bytes is not None:
log.error(err_bytes.decode('utf-8'))
return None
return eval(score_string)
但是,当它在子流程中遇到错误时,它不会打印到stderr
时的任何输出。我所看到的是:
2019-02-18 17:29:18 ERROR Invocation of train_model on Transcriptic ../data/pipeline/experiment.r1bbm2c4eyvsp_amazed-sponge_mefl_hist\
.csv ../data/trained/pipeline_mefl_hist/ failed with error 1.
2019-02-18 17:29:18 ERROR Error output is:
2019-02-18 17:29:18 ERROR
我怀疑我如何调用check_output
,特别是stderr
参数时遇到了问题。我已经阅读了文档,但是看不懂。我相信我必须做一些事情以捕捉stderr
,以便将其插入CalledProcessError
,但是我不知道该怎么做。