moleculekit.viewer.molstar.server module#
Singleton HTTP server with SSE for the molstar viewer.
- class moleculekit.viewer.molstar.server.ServerState(port, session, httpd, server_thread, monitor_thread, registry, subscribers, subscribers_lock, stop_event, handler_threads)#
Bases:
objectRuntime state of the singleton molstar viewer server.
- httpd#
The running HTTP server instance.
- Type:
ThreadingHTTPServer
- server_thread#
Daemon thread running
httpd.serve_forever.- Type:
- monitor_thread#
Daemon thread polling the registry for changes and broadcasting events.
- Type:
- registry#
The slot registry of molecules being served.
- Type:
Registry
- subscribers#
One queue per connected SSE client, fed serialized event payloads.
- Type:
listofqueue.Queue
- subscribers_lock#
Guards
subscribersandhandler_threads.- Type:
- stop_event#
Set on shutdown to stop the monitor loop and SSE handlers.
- Type:
- handler_threads#
Threads currently serving SSE streams, joined during shutdown.
- Type:
- httpd: ThreadingHTTPServer#
- subscribers_lock: allocate_lock#
- moleculekit.viewer.molstar.server.get_or_start_server(open_browser=True)#
Start the singleton server on first call; subsequent calls are no-ops.
- Parameters:
open_browser (
bool) – Whether to open a browser tab to the viewer when the server first starts. Defaults to True.- Returns:
state – The running server state (the same instance on every call).
- Return type:
- moleculekit.viewer.molstar.server.get_registry()#
Return the running server’s slot registry, starting the server if needed.
- Returns:
registry – The singleton server’s slot registry.
- Return type:
- moleculekit.viewer.molstar.server.register(mol)#
Register a Molecule with the running server and broadcast it.
Starts the server if it is not already running, registers
molin the registry and broadcasts a topology event to connected viewers.
- moleculekit.viewer.molstar.server.start_for_tests(open_browser=False)#
- Return type: