These functions are used for internal LensKit infrastructure code to persist models into shared memory for parallel processing.
- lenskit.sharing.persist(model, *, method=None)
Persist a model for cross-process sharing.
This will return a persisted model that can be used to reconstruct the model in a worker process (using
If no method is provided, this function automatically selects a model persistence strategy from the the following, in order:
If LK_TEMP_DIR is set, use
binpicklein shareable mode to save the object into the LensKit temporary directory.
binpicklein shareable mode to save the object into the system temporary directory.
- class lenskit.sharing.PersistedModel
A persisted model for inter-process model sharing.
These objects can be pickled for transmission to a worker process.
Subclasses need to override the pickling protocol to implement the proper pickling implementation.
- abstract get()
Get the persisted model, reconstructing it if necessary.
- abstract close()
Release the persisted model resources. Should only be called in the parent process (will do nothing in a child process).
Mark an object for ownership transfer. This object, when pickled, will unpickle into an owning model that frees resources when closed. Used to transfer ownership of shared memory resources from child processes to parent processes. Such an object should only be unpickled once.
The default implementation sets the