当前位置: 首页>>代码示例>>Python>>正文


Python ExecutePreprocessor.startup_timeout方法代码示例

本文整理汇总了Python中nbconvert.preprocessors.ExecutePreprocessor.startup_timeout方法的典型用法代码示例。如果您正苦于以下问题:Python ExecutePreprocessor.startup_timeout方法的具体用法?Python ExecutePreprocessor.startup_timeout怎么用?Python ExecutePreprocessor.startup_timeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nbconvert.preprocessors.ExecutePreprocessor的用法示例。


在下文中一共展示了ExecutePreprocessor.startup_timeout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_notebook

# 需要导入模块: from nbconvert.preprocessors import ExecutePreprocessor [as 别名]
# 或者: from nbconvert.preprocessors.ExecutePreprocessor import startup_timeout [as 别名]
    def run_notebook(source_path, output_file, serial_file, **analyzer_kwargs):
        template_path = pkg_resources.resource_filename('yank', 'reports/YANK_Health_Report_Template.ipynb')
        with open(template_path, 'r') as template:
            notebook_text = re.sub('STOREDIRBLANK', source_path, template.read())
            notebook_text = re.sub('ANALYZERKWARGSBLANK', str(analyzer_kwargs), notebook_text)
            if serial_file is not None:
                # Uncomment the line. Traps '#' and the rest, reports only the rest
                notebook_text = re.sub(r"(#)(report\.dump_serial_data\('SERIALOUTPUT'\))", r'\2', notebook_text)
                notebook_text = re.sub('SERIALOUTPUT', serial_file, notebook_text)

        # Cast to static output
        print("Rendering notebook as a {} file...".format(file_extension))
        import nbformat
        from nbconvert.preprocessors import ExecutePreprocessor
        import nbconvert.exporters
        # Categorize exporters based on extension, requires exporter object and data type output
        # 'b' = byte types output, e.g. PDF
        # 't' = text based output, e.g. HTML or even raw notebook, human-readable-like
        exporters = {
            ".pdf": {'exporter': nbconvert.exporters.PDFExporter, 'write_type': 'b'},
            ".html": {'exporter': nbconvert.exporters.HTMLExporter, 'write_type': 't'},
            ".ipynb": {'exporter': nbconvert.exporters.NotebookExporter, 'write_type': 't'}
        }

        # Load the notebook through Jupyter.
        loaded_notebook = nbformat.read(io.StringIO(notebook_text), as_version=4)
        # Process the notebook.
        ep = ExecutePreprocessor(timeout=None)
        # Sometimes the default startup timeout exceed the default of 60 seconds.
        ep.startup_timeout = 180
        # Set the title name, does not appear in all exporters
        _, output_file_name = os.path.split(output_file)
        resource_data = {'metadata': {'name': 'YANK Simulation Report: {}'.format(output_file_name)}}
        print("Processing notebook now, this may take a while...")
        processed_notebook, resources = ep.preprocess(loaded_notebook, resource_data)

        # Retrieve exporter
        exporter_data = exporters[file_extension.lower()]
        # Determine exporter and data output type
        exporter = exporter_data['exporter']
        write_type = exporter_data['write_type']
        with open(output_file, 'w{}'.format(write_type)) as notebook:
            exported_notebook, _ = nbconvert.exporters.export(exporter, processed_notebook, resources=resources)
            notebook.write(exported_notebook)
开发者ID:choderalab,项目名称:yank,代码行数:46,代码来源:analyze.py


注:本文中的nbconvert.preprocessors.ExecutePreprocessor.startup_timeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。