Skip to content

testsuite.worker

Simulators in their own processes.

SimulatorWorker starts a process (spawn context, so nothing of the parent is inherited) which runs the functions of sbml2cellml.testsuite.simulators on request. Every call has a timeout; a worker which times out or dies is replaced, so one bad case never takes the suite down.

Starting a process (spawn context) means importing sbml2cellml.testsuite.simulators from scratch, which can take a while when the machine is busy. To keep that startup cost out of the call timeout, the worker process sends a "ready" handshake on its connection right before it starts serving requests; SimulatorWorker.start waits for that handshake with its own generous STARTUP_TIMEOUT, separate from the per-call timeout used by SimulatorWorker.call.

SimulationFailure

Bases: RuntimeError

The simulator raised or the worker died.

SimulationTimeout

Bases: SimulationFailure

The simulator did not answer within the timeout.

SimulatorWorker

SimulatorWorker(name, timeout=60.0)

A simulator running in its own process.

Create the worker, not started yet.

Parameters:

Name Type Description Default
name str

name for the logs, e.g. roadrunner.

required
timeout float

seconds a call may take before the worker is replaced.

60.0

start

start()

Start the process and wait for its ready handshake.

Raises:

Type Description
SimulationFailure

if the process does not send the "ready" handshake within STARTUP_TIMEOUT; the process is killed.

stop

stop()

Stop the process.

call

call(function, **kwargs)

Run a function of sbml2cellml.testsuite.simulators in the worker.

Parameters:

Name Type Description Default
function str

name of the function.

required
**kwargs Any

its arguments, picklable.

{}

Returns:

Type Description
dict[str, Any]

The result dictionary of the function.

Raises:

Type Description
SimulationTimeout

if the call exceeds the timeout; the worker is replaced.

SimulationFailure

if the function raised, does not exist, or the worker died; a dead worker is replaced.

frame

frame(result)

Data frame of a simulator result.

Parameters:

Name Type Description Default
result dict[str, Any]

columns and rows as returned by the simulator functions.

required

Returns:

Type Description
DataFrame

The rows as data frame.