Skip to content

Isolator

QuantConnect.Isolator

Isolator()

Bases: Object

Isolator class - create a new instance of the algorithm and ensure it doesn't exceed memory or time execution limits.

Initializes a new instance of the Isolator class

cancellation_token_source

cancellation_token_source: CancellationTokenSource

Algo cancellation controls - cancel source.

execute_with_time_limit

execute_with_time_limit(
    time_span: timedelta,
    within_custom_limits: Callable[[], IsolatorLimitResult],
    code_block: Callable[[], Any],
    memory_cap: int = 1024,
    sleep_interval_millis: int = 1000,
    worker_thread: WorkerThread = None,
) -> bool
execute_with_time_limit(
    time_span: timedelta,
    code_block: Callable[[], Any],
    memory_cap: int,
    sleep_interval_millis: int = 1000,
    worker_thread: WorkerThread = None,
) -> bool

Execute a code block with a maximum limit on time and memory.

Parameters:

Name Type Description Default
time_span timedelta

Timeout in timespan

required
within_custom_limits Optional[Callable[[], IsolatorLimitResult]]

Function used to determine if the code_block is within custom limits, such as with algorithm manager

None
code_block Callable[[], Any]

Action codeblock to execute

required
memory_cap int

Maximum memory allocation, default 1024Mb

1024
sleep_interval_millis int

Sleep interval between each check in ms

1000
worker_thread WorkerThread

The worker thread instance that will execute the provided action, if null

None

Returns:

Type Description
bool

True if algorithm exited successfully, false if cancelled because it exceeded limits.