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.

貢獻者指南