Session

class narupatools.app.session.Session(target: Optional[TTarget] = None, *, autoplay: bool = True, **kwargs: Any)

Narupa server bundled with the ability to change what is being displayed.

A session has one target at a time, which can be a simulation, trajectory or a single frame.

The session has a background loop which periodically gets a FrameData to send to the clients. If the target implements FrameSource, this indicates the target can produce a frame and this will be sent to the clients. This background loop only sends fields which have been marked as dirty. Unlike Narupa, this means the sending of frames is completely detached from the MD loop, and hence can be specified in real time.

Inheritance

Inheritance diagram of Session

Methods

__init__

Create a session.

check_task

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

close

Remove the current target and close down the server and background tasks.

health_check

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

pause

Pause the target if it is a playable object.

play

Play the target if it is a playable object.

restart

Restart the target if it is a playable object.

run

Run the target if it is a playable object.

show

Broadcast an object, replacing the previous target if present.

start

Start a session as a context manager, calling close() after completion.

start_loop

Run an infinite loop waiting for a keyboard interruption.

step

Step the target if it is a playable object.

stop

Stop the target if it is a playable object.

__init__(target: Optional[TTarget] = None, *, autoplay: bool = True, **kwargs: Any)

Create a session.

Parameters
  • autoplay – If the target is playable, should it be automatically started if its not running.

  • kwargs – Parameters to initialise the server with.

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.

close()None

Remove the current target and close down the server and background tasks.

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()None

Pause the target if it is a playable object.

play()None

Play the target if it is a playable object.

restart()None

Restart the target if it is a playable object.

run(*, block: bool = False)None

Run the target if it is a playable object.

Raises

RuntimeError – The target is not an instance of Playable.

Parameters

block – Should this be run in blocking mode.

show(target: TTarget, /)None

Broadcast an object, replacing the previous target if present.

Parameters

target – Object to start broadcasting.

classmethod start(**kwargs: Any)Generator[narupatools.app.session.Session, None, None]

Start a session as a context manager, calling close() after completion.

Parameters

kwargs – Arguments to pass to the session.

start_loop()None

Run an infinite loop waiting for a keyboard interruption.

This checks the health of the session every second to catch any exceptions occurring on one of the background threads.

step()None

Step the target if it is a playable object.

stop()None

Stop the target if it is a playable object.

Attributes

address

URL or IP address the server is broadcasting at.

app

Underlying Narupa application.

name

Name of the session.

port

Port the session is broadcasting on.

shared_state

Shared state of the session.

target

Target which is being broadcast by this session.

address

URL or IP address the server is broadcasting at.

app

Underlying Narupa application.

name

Name of the session.

port

Port the session is broadcasting on.

shared_state

Shared state of the session.

target

Target which is being broadcast by this session.