bokeh.application.handlers.code_runner#

Provide a utility class CodeRunner for use by handlers that execute Python source code.

class CodeRunner(source: str, path: PathLike, argv: list[str], package: ModuleType | None = None)[source]#

Compile and run Python source code.

__init__(source: str, path: PathLike, argv: list[str], package: ModuleType | None = None) None[source]#
Parameters:
  • source (str) – A string containing Python source code to execute

  • path (str) – A filename to use in any debugging or error output

  • argv (list[str]) – A list of string arguments to make available as sys.argv when the code executes

  • package (bool) – An optional package module to configure

Raises:

ValueError, if package is specified for an __init__.py

new_module() ModuleType | None[source]#

Make a fresh module to run in.

Returns:

Module

reset_run_errors() None[source]#

Clears any transient error conditions from a previous run.

Returns

None

run(module: ModuleType, post_check: Callable[[], None] | None = None) None[source]#

Execute the configured source code in a module and run any post checks.

Parameters:
  • module (Module) – A module to execute the configured code in.

  • post_check (callable, optional) – A function that raises an exception if expected post-conditions are not met after code execution.

property doc: str | None#

Contents of docstring, if code contains one.

property error: str | None#

If code execution fails, may contain a related error message.

property error_detail: str | None#

If code execution fails, may contain a traceback or other details.

property failed: bool#

True if code execution failed

property path: str | PathLike[str]#

The path that new modules will be configured with.

property source: str#

The configured source code that will be executed when run is called.