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

Methods
Create a session.
Check if a task has thrown an exception, and reraise it if so.
Remove the current target and close down the server and background tasks.
Check background tasks to ensure they have not encountered an exception.
Pause the target if it is a playable object.
Play the target if it is a playable object.
Restart the target if it is a playable object.
Run the target if it is a playable object.
Broadcast an object, replacing the previous target if present.
Start a session as a context manager, calling close() after completion.
Run an infinite loop waiting for a keyboard interruption.
Step the target if it is a playable object.
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.
-
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.
-
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.
Attributes
URL or IP address the server is broadcasting at.
Underlying Narupa application.
Name of the session.
Port the session is broadcasting on.
Shared state of the session.
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 of the session.
-
target¶ Target which is being broadcast by this session.
-