hertzforge.service.server¶
server
¶
The analysis service: sds/1 over WebSocket.
On connect the server sends hello. Each request is answered by a
response with its id; requests run concurrently, so a long project.open
does not hold up a catalog.list sent after it, and responses may come
back in a different order from the requests. Heavy work (opening a
project, running an operation, framing a large result) runs in a worker
thread so the event loop stays responsive.
Each connection has at most one project of its own (project.*), which
every operation runs on and which ends with it. Table files (tables.*) are
read and written by path beside it, without touching it.
A plain HTTP request, one that does not ask to upgrade to WebSocket, is
answered with the shell's built pages when the package carries them
(shell_folder), so hertzforge with no command can open the interface in
a browser from a pip install.
Classes:
| Name | Description |
|---|---|
Service |
Everything but the transport: the operations and the worker |
Connection |
One client: its project, its requests in flight, and the lock that |
Functions:
| Name | Description |
|---|---|
preload |
Import everything in |
shell_folder |
The shell's built pages: |
shell_response |
The file a plain GET asks for from the shell's |
start |
A listening server (port 0 picks a free one; |
Classes¶
Service
¶
Service(operations: Sequence[Operation] = OPERATIONS, workers: int = 2, dialogs: bool = False)
Everything but the transport: the operations and the worker threads. One per process.
Methods:
| Name | Description |
|---|---|
close |
Stop the worker threads without waiting; work not yet started is |
in_worker |
|
catalog_list |
The |
operation |
The operation an |
Connection
¶
Connection(service: Service, socket: ServerConnection)
One client: its project, its requests in flight, and the lock that keeps its frames whole.
Methods:
| Name | Description |
|---|---|
send |
Send one frame, under the lock, so concurrent responses never |
event |
Send one event on |
progress |
A (done, total) callable for a reader on a worker thread that |
op_progress |
A (done, total) callable for an operation on a worker thread: it sends |
cancel_op |
|
project_request |
Answer one |
project_op |
An operation on this connection's project: its views and the |
report_request |
Answer one |
fit_state |
The fit's state with its CMIF drawn in this connection's units. |
units_request |
|
fit_request |
Answer one |
serve |
Send |
choose_files |
|
answer |
Run one request and send its response. A ProtocolError becomes an |
Attributes:
| Name | Type | Description |
|---|---|---|
system |
Any
|
The |
Attributes¶
Methods:¶
send
async
¶
Send one frame, under the lock, so concurrent responses never interleave on the socket.
event
async
¶
Send one event on topic, numbered in this connection's order.
progress
¶
A (done, total) callable for a reader on a worker thread that
sends project.progress events, at most one per
PROGRESS_INTERVAL_S and always the last.
op_progress
¶
A (done, total) callable for an operation on a worker thread: it sends
op.progress events, at most one per PROGRESS_INTERVAL_S but always when the stage or
its total changes and at the end, and raises Cancelled once op.cancel is asked.
cancel_op
¶
op.cancel: stop the operation running on the project at its next report of
progress. Answers which operation that is, or null when none is running.
project_request
async
¶
Answer one project.* request on this connection's project, after
any still running.
project_op
async
¶
An operation on this connection's project: its views and the project's summary, which counts as modified when the operation added or removed an object.
report_request
async
¶
Answer one report.* request on this connection's project.
fit_state
¶
fit_state(fit: Fit) -> dict[str, Any]
The fit's state with its CMIF drawn in this connection's units.
units_request
¶
units.system: the unit system this connection's views are drawn
in, set when name is given; the systems there are.
fit_request
async
¶
Answer one fit.* request: a step of the mode fit on this
connection's project, and the fit's state after it.
serve
async
¶
Send hello, then answer each request in its own task until the
client goes. A frame that will not decode closes the connection with
1007, a message that is not a request with an integer id with 1008;
requests still running when it ends are cancelled.
choose_files
async
¶
files.choose: the system's open or save dialog on this machine, and the
paths chosen in it (none when cancelled). Refused where the service shows no
dialogs or none can be shown here, so the shell asks for a typed path.
answer
async
¶
Run one request and send its response. A ProtocolError becomes an
error response with its code; any other exception is logged and sent
as internal, so one failing request never ends the connection.
Functions:¶
shell_folder
¶
The shell's built pages: hertzforge/shell in an installed package
(the release workflow builds it into the wheel), else ui/build in a
source checkout after npm --prefix ui run build. None when neither
holds an index.html.
shell_response
¶
The file a plain GET asks for from the shell's folder, or None for
a WebSocket upgrade, which the protocol handles. The shell is a
single-page app, so a path with no suffix gets index.html; a missing
file with a suffix is a 404, and nothing outside folder is served.
start
async
¶
start(service: Service, host: str = '127.0.0.1', port: int = 8791, shell: Path | None = None) -> Server
A listening server (port 0 picks a free one; server.sockets says
which). With shell, a plain HTTP request is answered from that folder
of built pages (shell_response). It changes nothing beyond the server:
the process that serves calls preload and sets SWITCH_INTERVAL first
(__main__._serve).