composeui.core.shared¶
Data loaded once per process and shared by its sessions, read-only (see shared_data).
- class composeui.core.shared.SharedData[source]¶
Bases:
Generic[R,ProgressT]A value loaded once per process, given to each session’s job: see
shared_data.Pass it to
Jobs.taskorJobs.startas the job’s function. The first job starts the load in a thread of its own, the jobs that come meanwhile wait for it, and later jobs get the value at once. Each job reports the load’s progress. A job canceled stops waiting and raisesJobCanceledError; the load stops once no job waits for it. A failed load is not kept: the next job loads again.
- exception composeui.core.shared.SharedDataError[source]¶
Bases:
ExceptionA shared load returned a value that a session could change, so it isn’t shared.
- composeui.core.shared.shared_data(load)[source]¶
Load
load’s value once per process, and share it with every session, read-only.A decorator, e.g. of a function reading a large CSV, which each session’s job then gets without reading it again.
loadtakes only its job: its value can’t depend on a session’s input, which would share private data. The value is protected once loaded, or refused (SharedDataError) if a session could change it:a Polars frame or series: each session gets a clone, which shares its columns;
a pandas frame or series, with pandas’ copy-on-write on: a copy per session;
a NumPy array: read-only, with the arrays it’s a view of, but not one over memory that can be written, e.g. a
bytearray;a Polars lazy frame, a PyArrow table or chunked array: as it is;
an immutable value: a number, a string, a date, None, an enum member, or a tuple, frozenset or frozen attrs class of them.
- Parameters:
- Return type:
SharedData[R, ProgressT]