JsonFileStore#

class scikitplot.agent.JsonFileStore(directory)[source]#

Keep each run’s state in <directory>/<run_id>.json.

Parameters:
directorystr or os.PathLike

Created if missing.

Parameters:

directory (str | os.PathLike[str])

Notes

A save writes a temporary file in the same directory, syncs it, renames it over the old one (os.replace) and syncs the directory, so a reader sees the old state or the new one, never a partial file, and the new one survives a power loss once save returns. The run id is checked to be 64 hexadecimal digits before it names a file, so it cannot name one outside directory.

has(run_id)[source]#

Whether a state file of run_id exists.

Parameters:

run_id (str)

Return type:

bool

load(run_id)[source]#

Read run_id’s state.

Parameters:

run_id (str)

Return type:

RunState

path(run_id)[source]#

Return the file that holds run_id’s state.

Parameters:

run_id (str)

Return type:

Path

run_ids()[source]#

Return the ids of the runs kept, sorted.

Return type:

tuple[str, …]

save(state)[source]#

Write state atomically.

Parameters:

state (RunState)

Return type:

None