Playable

class narupatools.core.playable.Playable(*, playback_interval: float = 0.1)

Object that can be run at a target frame rate with playback controls..

Playables can therefore both represent trajectories (where there are a set number of frames which are played through one by one) and simulations (which generate frames one at a time).

Playables support pausing, restarting and stepping, as well as execution in both background and foreground threads.

Inheritance

Inheritance diagram of Playable

Methods

__init__

Create a new playable.

check_task

Check if a task has thrown an exception, and reraise it if so.

health_check

Check background tasks to ensure they have not encountered an exception.

pause

Pause this object if it is running.

play

Play the given object.

restart

Restart this back to its initial state.

run

Run this object, potentially in a background thread.

start

An alias for run().

step

Step forward by one step, and then pause the simulation.

stop

Stop the object if it is running.

__init__(*, playback_interval: float = 0.1)

Create a new playable.

Parameters

playback_interval – Target interval to run this playable at.

classmethod check_task(task: Optional[concurrent.futures._base.Future])None

Check if a task has thrown an exception, and reraise it if so.

Parameters

task – Background task to check for an exception.

health_check()None

Check background tasks to ensure they have not encountered an exception.

Calling this allows exceptions raised on background threads to be thrown on the main thread. It is a useful tool for checking if an object has crashed silently in the background.

It is recommended to call this periodically from the main thread to ensure an object is healthy. If no exceptions have occurred, this method will do nothing.

pause(wait: bool = True)None

Pause this object if it is running.

This will not cancel the current run if present, merely suspend it until a subsequent call to play() is made.

Parameters

wait – Wait until the pause has actually occurred.

play()None

Play the given object.

If this is not running, run this on a background thread. Else, unpause if this is paused.

restart()None

Restart this back to its initial state.

run(block: Literal[True])bool
run(block: Literal[False])concurrent.futures._base.Future[bool]
run(block: bool)Union[bool, concurrent.futures._base.Future[bool]]

Run this object, potentially in a background thread.

If block is True (as is the default), this object will run in the calling thread. If block is False, it will be run in a background thread.

Parameters

block – Should this block?

Raises

PlayableAlreadyRunningError – Playable is running on another thread.

Returns

If run in blocking mode, returns True if the playable completed and False if it was stopped. If run in non-blocking mode, returns a Future with the same result.

start(block: bool = True)None

An alias for run().

Parameters

block – Should this block?

step()None

Step forward by one step, and then pause the simulation.

stop(wait: bool = True)None

Stop the object if it is running.

If this is running, this object will stop executing at the next available point.

Parameters

wait – Should this call wait until this object has stopped running before returning?

Attributes

is_paused

Is this currently running but paused?

is_playing

Is this currently playing and not paused?

is_running

Is this currently running?

playback_interval

Time in seconds between individual steps of this playable.

playback_rate

Number of steps this playable goes through in 1 second.

is_paused

Is this currently running but paused?

is_playing

Is this currently playing and not paused?

is_running

Is this currently running?

This is True even if the playback is paused.

playback_interval

Time in seconds between individual steps of this playable.

playback_rate

Number of steps this playable goes through in 1 second.