def reuse_if_mtime_is_today() -> Callable[[datetime.datetime], bool]:
"""
A helper that returns a lambda appropriate for use in the
def reuse_if_mtime_is_today() -> Callable[[datetime.datetime], bool]:
"""
A helper that returns a lambda appropriate for use in the
parameter that allows persisted state to be reused as long as it
was persisted on the same day as the load.
parameter that allows persisted state to be reused as long as it
was persisted on the same day as the load.
limit_seconds: int
) -> Callable[[datetime.datetime], bool]:
"""
A helper that returns a lambda appropriate for use in the
limit_seconds: int
) -> Callable[[datetime.datetime], bool]:
"""
A helper that returns a lambda appropriate for use in the
parameter that allows persisted state to be reused as long as it
was persisted within the past limit_seconds.
parameter that allows persisted state to be reused as long as it
was persisted within the past limit_seconds.
class PersistAtShutdown(enum.Enum):
"""
An enum to describe the conditions under which state is persisted
class PersistAtShutdown(enum.Enum):
"""
An enum to describe the conditions under which state is persisted
"""This class is meant to be used as a decorator around a class that:
1. Is a singleton; one global instance per python program.
"""This class is meant to be used as a decorator around a class that:
1. Is a singleton; one global instance per python program.
- may_reuse_persisted = reuse_if_mtime_less_than_limit(60),
- persist_at_shutdown = False
+ may_reuse_persisted = reuse_if_mtime_less_than_limit_sec(60),
+ persist_at_shutdown = PersistAtShutdown.IF_NOT_INITIALIZED_FROM_DISK,
it exists and any may_reuse_persisted predicate indicates
that reusing persisted state is allowed, we will skip the
call to __init__ and return an unpickled instance read from
it exists and any may_reuse_persisted predicate indicates
that reusing persisted state is allowed, we will skip the
call to __init__ and return an unpickled instance read from
- the persisted state cannot be reused, MyComplexObject's
- __init__ will be invoked and will be expected to fully
- initialize the instance.
+ the persisted state cannot be reused (e.g. too stale),
+ MyComplexObject's __init__ will be invoked and will be
+ expected to fully initialize the instance.
4. At program exit time, depending on the value of the
persist_at_shutdown parameter, the state of MyComplexObject
will be written to disk using the same filename so that
future instances may potentially reuse saved state. Note
that the state that is persisted is the state at program
4. At program exit time, depending on the value of the
persist_at_shutdown parameter, the state of MyComplexObject
will be written to disk using the same filename so that
future instances may potentially reuse saved state. Note
that the state that is persisted is the state at program