Add support for no `._first.value` update shm prepends
parent
c07aa76201
commit
66c20b80a5
|
@ -40,10 +40,11 @@ log = get_logger(__name__)
|
||||||
|
|
||||||
# how much is probably dependent on lifestyle
|
# how much is probably dependent on lifestyle
|
||||||
_secs_in_day = int(60 * 60 * 24)
|
_secs_in_day = int(60 * 60 * 24)
|
||||||
# we try for 3 times but only on a run-every-other-day kinda week.
|
# we try for a buncha times, but only on a run-every-other-day kinda week.
|
||||||
_default_size = 20 * _secs_in_day
|
_days_worth = 16
|
||||||
|
_default_size = _days_worth * _secs_in_day
|
||||||
# where to start the new data append index
|
# where to start the new data append index
|
||||||
_rt_buffer_start = int(9*_secs_in_day)
|
_rt_buffer_start = int((_days_worth - 1) * _secs_in_day)
|
||||||
|
|
||||||
|
|
||||||
def cuckoff_mantracker():
|
def cuckoff_mantracker():
|
||||||
|
@ -61,13 +62,12 @@ def cuckoff_mantracker():
|
||||||
def ensure_running(self):
|
def ensure_running(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# "know your land and know your prey"
|
# "know your land and know your prey"
|
||||||
# https://www.dailymotion.com/video/x6ozzco
|
# https://www.dailymotion.com/video/x6ozzco
|
||||||
mantracker._resource_tracker = ManTracker()
|
mantracker._resource_tracker = ManTracker()
|
||||||
mantracker.register = mantracker._resource_tracker.register
|
mantracker.register = mantracker._resource_tracker.register
|
||||||
mantracker.ensure_running = mantracker._resource_tracker.ensure_running
|
mantracker.ensure_running = mantracker._resource_tracker.ensure_running
|
||||||
ensure_running = mantracker._resource_tracker.ensure_running
|
# ensure_running = mantracker._resource_tracker.ensure_running
|
||||||
mantracker.unregister = mantracker._resource_tracker.unregister
|
mantracker.unregister = mantracker._resource_tracker.unregister
|
||||||
mantracker.getfd = mantracker._resource_tracker.getfd
|
mantracker.getfd = mantracker._resource_tracker.getfd
|
||||||
|
|
||||||
|
@ -262,10 +262,10 @@ class ShmArray:
|
||||||
|
|
||||||
if fields:
|
if fields:
|
||||||
selection = array[fields]
|
selection = array[fields]
|
||||||
fcount = len(fields)
|
# fcount = len(fields)
|
||||||
else:
|
else:
|
||||||
selection = array
|
selection = array
|
||||||
fcount = len(array.dtype.fields)
|
# fcount = len(array.dtype.fields)
|
||||||
|
|
||||||
# XXX: manual ``.view()`` attempt that also doesn't work.
|
# XXX: manual ``.view()`` attempt that also doesn't work.
|
||||||
# uview = selection.view(
|
# uview = selection.view(
|
||||||
|
@ -308,6 +308,7 @@ class ShmArray:
|
||||||
|
|
||||||
field_map: Optional[dict[str, str]] = None,
|
field_map: Optional[dict[str, str]] = None,
|
||||||
prepend: bool = False,
|
prepend: bool = False,
|
||||||
|
update_first: bool = True,
|
||||||
start: Optional[int] = None,
|
start: Optional[int] = None,
|
||||||
|
|
||||||
) -> int:
|
) -> int:
|
||||||
|
@ -320,10 +321,9 @@ class ShmArray:
|
||||||
|
|
||||||
'''
|
'''
|
||||||
length = len(data)
|
length = len(data)
|
||||||
index = start if start is not None else self._last.value
|
|
||||||
|
|
||||||
if prepend:
|
if prepend:
|
||||||
index = self._first.value - length
|
index = (start or self._first.value) - length
|
||||||
|
|
||||||
if index < 0:
|
if index < 0:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
@ -331,6 +331,9 @@ class ShmArray:
|
||||||
f'You have passed {abs(index)} too many datums.'
|
f'You have passed {abs(index)} too many datums.'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
index = start if start is not None else self._last.value
|
||||||
|
|
||||||
end = index + length
|
end = index + length
|
||||||
|
|
||||||
if field_map:
|
if field_map:
|
||||||
|
@ -348,12 +351,17 @@ class ShmArray:
|
||||||
# tries to access ``.array`` (which due to the index
|
# tries to access ``.array`` (which due to the index
|
||||||
# overlap will be empty). Pretty sure we've fixed it now
|
# overlap will be empty). Pretty sure we've fixed it now
|
||||||
# but leaving this here as a reminder.
|
# but leaving this here as a reminder.
|
||||||
if prepend:
|
if prepend and update_first:
|
||||||
assert index < self._first.value
|
assert index < self._first.value
|
||||||
|
|
||||||
if index < self._first.value:
|
if (
|
||||||
|
index < self._first.value
|
||||||
|
and update_first
|
||||||
|
):
|
||||||
|
assert prepend, 'prepend=True not passed but index decreased?'
|
||||||
self._first.value = index
|
self._first.value = index
|
||||||
else:
|
|
||||||
|
elif not prepend:
|
||||||
self._last.value = end
|
self._last.value = end
|
||||||
|
|
||||||
self._post_init = True
|
self._post_init = True
|
||||||
|
@ -389,6 +397,7 @@ class ShmArray:
|
||||||
f"Input array has unknown field(s): {only_in_theirs}"
|
f"Input array has unknown field(s): {only_in_theirs}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO: support "silent" prepends that don't update ._first.value?
|
||||||
def prepend(
|
def prepend(
|
||||||
self,
|
self,
|
||||||
data: np.ndarray,
|
data: np.ndarray,
|
||||||
|
|
Loading…
Reference in New Issue