ReconProxy#
- class pulserver.proxy.ReconProxy[source]#
Bases:
objectRoutes each series of an MRD stream to a reconstruction.
One thread per client connection, which carries one series: an optional config text, the header, one acquisition per readout of the chain and a
CLOSE. The header’spulserver_designnames the design of the store the series was played from; its readout table enriches the header and every acquisition, and the reconstruction receives the chain’s sequence description as a text message after the header and before the first acquisition (message()), which is not sent back to the client. The readouts arrive demodulated to the prescribed field-of-view centre by the playout (pulserver.ir.prescribe()), and their samples are passed on as received. The reconstruction plugin is the one the client’s config text names. A series that breaks this is refused with a text naming the reason and aCLOSE, and what the client still sends is discarded until it closes the connection.The enriched series is reconstructed by a local worker, or, with
forward, by the MRD server at that address. Whatever reconstructs it, its images, DICOM and text go back to the client as they arrive, the client’s close closes the reconstruction’s stream, and the reconstruction’s close closes the client. A message the proxy has no reader for ends what goes back, with a text naming its type. Once the client’s stream ends, the proxy waits for the reconstruction to close, however long it takes, unlessrecon_timeoutcaps it.A local series holds a slot for as long as it runs. On a host with GPUs, found through
CUDA_VISIBLE_DEVICESornvidia-smi, each slot holds one,gpu_slotsslots per GPU, and the reconstruction reads it ascontext.device. A series that finds every slot busy is queued instead: its enriched stream is written to a file ofqueuewhile it arrives, its client stays connected, and the file is replayed to a worker and deleted once a slot frees. The series of one exam share a directory under the system’s temporary directory, through which a reconstruction reads what an earlier series of the exam stored in itsExamCache. It is deleted once a header names another exam, or nothing has leased it forEXAM_IDLEseconds, and no series of the exam still runs on any proxy.A series whose sequence sets
EnablePmcis corrected for motion while it plays: the poses its reconstruction states are published into the pose file the scan reads,motion.bufin the design’s directory, rather than sent to the client. A forwarded series publishes the poses the server passes back.What goes back to a client is also written to a directory under the system’s temporary directory, shared with every other proxy on this host, and removed once the client has had all of it. When the client has gone, it is kept: a client opening a series with the same
measurementIDis sent it, after it is complete, in place of a new reconstruction. Kept output nobody takes up is removed after a day.A forwarded series is sent on as it arrives; the server’s own slots and queue determine when it is reconstructed. The server is sent a config file message naming
forward_config, or else the series’ reconstruction plugin; the client’s config text itself is not forwarded.- Parameters:
store – Directory of designs, as the design calls write it; read only.
plugins – Directories of reconstruction plugin files,
<plugin>.py, in search order; required unless the proxy forwards.slots – Series reconstructed at once; derived from memory and the GPUs when
None.gpu_slots – Series reconstructed at once on each GPU, when
slotsisNone.spares – Warm worker processes waiting for a series.
recon_timeout – Seconds a reconstruction may take after the stream ends before it is stopped and the client told so;
Nonewaits for its close. A local worker is terminated; a forwarded series’ connection is closed.queue – Directory the queued series are written to; a temporary directory, removed on
close(), whenNone.slot_directory – Directory the slots are held in, shared with every other proxy on this host so they count against one set;
DEFAULT_SLOT_DIRECTORYwhenNone.exam_directory – Directory the caches of an exam are held in, shared with every other proxy on this host so a map one series measures reaches a series on another;
DEFAULT_EXAM_DIRECTORYwhenNone. An exam’s directory is removed when the last proxy on that exam lets go of it.forward –
(host, port)of the MRD server that reconstructs every series; local workers whenNone.forward_config – Config name sent to that server instead of the reconstruction plugin.
dicom – Convert each image to DICOM, from the enriched header, before it is relayed. Whatever reconstructed it: a client that reads DICOM alone, such as a scanner’s, needs this of a plugin that emits images.
- Attributes:
workers (WorkerPool | None) – The spares assignments are taken from;
Nonewhen forwarding.exams (ExamCacheManager | None) – The current exam and its directory;
Nonewhen forwarding.queue (Path | None) – The queue directory;
Nonewhen forwarding.
- Raises:
ValueError – If the proxy neither forwards nor has a plugin directory.
Methods
Listen on |
|
Stop accepting clients, wait for running series and release the spares. |
|
Accept clients until |
|
Make |
Attributes
Port the server listens on. |