跳到主要内容

coding.jupyter.jupyter_code_executor

JupyterCodeExecutor

class JupyterCodeExecutor(CodeExecutor)

__init__

def __init__(jupyter_server: Union[JupyterConnectable, JupyterConnectionInfo],
kernel_name: str = "python3",
timeout: int = 60,
output_dir: Union[Path, str] = Path("."))

(实验性) 一个代码执行类,该类使用提供给此类的Jupyter服务器有状态地执行代码。

每次执行都是有状态的,并且可以访问同一会话中先前执行创建的变量。

参数:

  • jupyter_server Union[JupyterConnectable, JupyterConnectionInfo] - 使用的 Jupyter 服务器。
  • timeout int - 代码执行的超时时间,默认为60。
  • kernel_name str - 要使用的内核名称。确保它已安装。 默认情况下,它是 "python3"。
  • output_dir str - 保存输出文件的目录,默认为 "."。

code_extractor

@property
def code_extractor() -> CodeExtractor

(实验性)导出一个可以被代理使用的代码提取器。

执行代码块

def execute_code_blocks(code_blocks: List[CodeBlock]) -> IPythonCodeResult

(实验性)执行一系列代码块并返回结果。

此方法在Jupyter内核中将一系列代码块作为单元执行。 参见: https://jupyter-client.readthedocs.io/en/stable/messaging.html 了解消息协议。

参数:

  • code_blocks List[CodeBlock] - 要执行的代码块列表。

返回:

  • IPythonCodeResult - 代码执行的结果。

重启

def restart() -> None

(实验性功能)重新开始一个新会话。

停止

def stop() -> None

停止内核。