papermill
papermill copied to clipboard
TraitError when running notebook
🐛 Bug
When I try to run a notebook using pm.execute_notebook it raises a TraitError as shown below. The error is raised in some environments but not in others. I've tried to use the same version of dependency packages but that didn't fix the problem.
Function:
def run_notebook(
nb_path: str,
raise_on_error: bool = True,
log_error: bool = False
) -> Tuple[str]:
if not nb_path.endswith('.ipynb'):
nb_path += '.ipynb'
with open("out.txt", "w+") as stdout, open("err.txt", "w+") as stderr:
try:
pm.execute_notebook(
input_path=nb_path,
output_path=nb_path + "_log.ipynb",
log_output=True,
stdout_file=stdout,
stderr_file=stderr
)
except pm.PapermillExecutionError as e:
stderr.write(str(e))
if raise_on_error is True:
raise eval(f"{e.ename}('{e.evalue}')")
else:
err_msg = (
f"{nb_path}: Erro na execução ignorado devido ao"
f" parâmetro raise_on_error:\n{e}"
)
print(err_msg)
finally:
stdout.seek(0), stderr.seek(0)
out = stdout.read()
err = stderr.read()
stdout.close()
stderr.close()
os.remove("out.txt")
os.remove("err.txt")
print(out, err)
Error:
TraitError: The 'log' trait of a PapermillNotebookClient instance must be a Logger, but a value of class 'logging.Logger' (i.e. <Logger papermill (DEBUG)>) was specified.