Utility functions around state changes.
Project description
Utility functions around state changes.
Latest release 20240316: Fixed release upload artifacts.
Function delta(old, new, keys=None)
Return a mapping representing differences between the mappings
old
and new
for the specified keys
.
If keys
is not specified, the union of the keys of old
and new
is used.
The returned mapping has a key for each changed value.
If the key does not exist in new
the value is the MISSING
sentinel object otherwise it is new[key]
.
Values are compared using ==
; if that raises TypeError
the values are considered not equal.
Example:
d1 = {1: 2, 3: 4, 5: 6} d2 = {1: 2, 3: 44, 7: 8} diff = delta(d1, d2) diff # doctest: +ELLIPSIS {3: 44, 5: <object object at ...>, 7: 8} diff[5] is MISSING True
Function monitor(get_state, keys=None, *, ifunchanged=False, interval=0.3, runstate=None)
A generator yielding 3-tuples of (old,new,delta(old,new,keys))
at poll intervals of interval
seconds.
Parameters:
get_state
: a callable which polls the current state, returning a mappingkeys
: an optional iterable of keys of interest; if omitted, all the old and new mapping keys are examinedifunchanged
: optional flag, defaultFalse
; if true yield a tuple on every poll instead of only when a state change is seeninterval
: an optional interpolltime.sleep
period, default0.3
srunstate
: an optionalRunState
, whosecancelled
attribute will be polled for loop termination
Release Log
Release 20240316: Fixed release upload artifacts.
Release 20240214: Initial PyPI release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cs.delta-20240316-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a8abcc6802c2e2cb2d390baccd1a53df722aa5a58f2e52e3d4de88f21057efc |
|
MD5 | 92b53bb0a2d427ece30920033adc04de |
|
BLAKE2b-256 | f9d0ce387add470fba87c02bf4d94b92ed089c7b5be7d03d1c56035dd0edd402 |