Skip to content

RuntimeConfig

Configuration for JavaScript runtime instances.

Use this to configure heap limits, execution timeouts, and bootstrap scripts before creating a Runtime.

__init__

__init__(max_heap_size: int | None = None, initial_heap_size: int | None = None, bootstrap: str | None = None, timeout: float | int | None = None, enable_console: bool | None = False, on_console: Callable[[str, list[Any]], Any] | None = None, inspector: InspectorConfig | None = None, snapshot: bytes | None = None, max_serialization_depth: int | None = None, max_serialization_bytes: int | None = None, force_kill_grace: float | int | timedelta | None = None, max_buffer_bytes: int | None = None) -> None

Create a new runtime configuration.

Parameters:

Name Type Description Default
max_heap_size int | None

Maximum JS heap size in bytes. Does not bound ArrayBuffer storage; see max_buffer_bytes.

None
initial_heap_size int | None

Initial heap size in bytes

None
bootstrap str | None

JavaScript source code to execute on startup

None
timeout float | int | None

Execution timeout in seconds (float or int). A fired deadline terminates whatever the isolate is running at that moment, which is not necessarily the job that timed out: the isolate is single-threaded and terminate_execution is isolate-wide, so if you run concurrent work on one runtime -- a synchronous call dispatched while an async job is parked on a promise, say -- the other job can be stopped instead, and reports a bare execution terminated error rather than a timeout. Use a runtime per concurrent job if you need a termination error to be about the call that raised it. A timeout is otherwise recoverable: the runtime stays usable afterwards, including when an async job times out on a still-pending promise (that promise simply stays pending).

None
enable_console bool | None

Whether console output reaches the process's stdout/stderr (defaults to False, which stubs console to no-ops). Independent of on_console.

False
on_console Callable[[str, list[Any]], Any] | None

Optional callable invoked as on_console(level, args) for every console.* call from guest JS. level is the method name ("log", "info", "warn", "error", "debug", "trace") and args is that call's argument list. Set it to route console output back to Python; combine with enable_console=True to also keep the process's own console output. Must be synchronous.

None
inspector InspectorConfig | None

Optional inspector configuration enabling Chrome DevTools

None
snapshot bytes | None

Optional V8 startup snapshot bytes

None
max_serialization_depth int | None

Maximum nesting depth when transferring values (default 100). Raising it past roughly 900 is unsafe if you then pass a deep argument from a small-stack thread: the Python-to-JS conversion recurses on the calling thread, and a threading.Thread gets 512 KB on macOS, which pydeno cannot change. The default has ~9x of headroom on such a thread; see RUNTIME_THREAD_STACK_SIZE in src/runtime/js_value.rs. The effective ceiling is also lower than whatever you set here when pydeno itself was built unoptimized: a debug build's serializer frames are ~33x larger, so a native stack-headroom backstop rejects nesting past roughly depth 22 there, well before this setting applies. Released wheels are optimized builds, where that backstop sits around depth 743 and this setting is always what you actually hit.

None
max_serialization_bytes int | None

Maximum serialized byte size when transferring values

None
force_kill_grace float | int | timedelta | None

How long a blocked caller waits for the runtime to acknowledge a termination before abandoning the runtime thread and raising RuntimeForceKilled. None (the default) waits forever. Only needed for a runtime wedged in a host callback that never returns; runaway JS and never-resolving promises are already bounded. Enabling it costs roughly 10% per synchronous call.

None

on_console property writable

on_console: Callable[[str, list[Any]], Any] | None

The configured console callback, if any.

max_heap_size property writable

max_heap_size: int | None

Maximum heap size in bytes.

max_buffer_bytes property writable

max_buffer_bytes: int | None

Cap on live ArrayBuffer / SharedArrayBuffer bytes (None = uncapped).

initial_heap_size property writable

initial_heap_size: int | None

Initial heap size in bytes.

bootstrap property writable

bootstrap: str | None

Bootstrap script to execute on runtime startup.

timeout property writable

timeout: float | None

Execution timeout in seconds.

enable_console property

enable_console: bool | None

Whether console APIs are enabled inside the runtime.

inspector property writable

inspector: InspectorConfig | None

Inspector configuration if debugging is enabled.

max_serialization_depth property writable

max_serialization_depth: int

Maximum recursion depth allowed when serializing values.

max_serialization_bytes property writable

max_serialization_bytes: int

Maximum byte size allowed when serializing values.

force_kill_grace property writable

force_kill_grace: float | None

Grace period in seconds before abandoning an unresponsive runtime.