nteract/papermill

TraitError when running notebook

开放

#655 创建于 2022年3月10日

 (0 条评论) (0 个反应) (0 位负责人)Python (402 个派生)batch import
bughelp wanted

仓库指标

星标
 (5,381 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

🐛 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.

贡献者指南