mux
BlockMuxStream ¶
BlockMuxStream(reader, start=None, timeout=0, on_gap=ONGAP_DEFAULT)
Bases: Generic[T]
A time-aware, gap-handling multiplexer for SeriesBlock streams.
Given SeriesBlocks from multiple named streams with monotonically increasing integer timestamps, this data structure can be used to pull out sets of synchronized blocks, all with the same timestamps. If data on the streams is not available before timeouts are reached, gap blocks will be returned.
The oldest items will be held until either all named streams are available or until the timeout has been reached. If a start time has been set, any items with an older timestamp will be rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reader
|
StreamReader
|
StreamReader object producing multiple stream to multiplex. |
required |
start
|
int
|
GPS start time of stream, in nanoseconds. |
None
|
timeout
|
int = 0
|
Overall timeout for the muxer, in nanoseconds. Overrides individual queue timeouts. If not specified the mux timeout will be the max of the individual queue timeouts. |
0
|
on_gap
|
str
|
Policy for strides in which no stream has any data. 'fill'
(default) emits masked gap blocks so the output timeline is
continuous; 'skip' emits nothing for such strides (sparse
output, no cost for absence); 'raise' raises |
ONGAP_DEFAULT
|
Source code in arrakis/mux.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
__getitem__ ¶
__getitem__(key)
Access an individual queue.
Source code in arrakis/mux.py
452 453 454 | |
pull ¶
pull()
Pull synchronized, concatenated, combined blocks from all streams covering the overall specified stride.
Returns:
| Type | Description |
|---|---|
SeriesBlock or None
|
The combined block for the next stride, or None if the
stride held no data and was skipped ( |
Source code in arrakis/mux.py
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
push ¶
push(stream_name, block)
Push an element for time into a particular queue.
Source code in arrakis/mux.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |
ready ¶
ready()
True if all queues have the expected number of elements
covering the overall muxer stride.
Source code in arrakis/mux.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
TimedQueue ¶
TimedQueue(stride, timeout, start=None)
Bases: Generic[T]
A sequential, time-stamped queue handling gaps and timeouts.
The queue stores only real elements; the spans between them are gaps, synthesized lazily when pulled. Two integer cursors define the queue state:
cursor: the next timestamp to be served by :meth:pull.horizon: the end (exclusive) of the known span. Every stride in[cursor, horizon)is either a stored element or a gap. Elements older than the horizon are rejected.
The horizon advances when an element is pushed (per-stream delivery is assumed to be in time order, so an element at time T implies nothing older is still coming) and, for live streams, when the timeout deadline passes (absence past the deadline is declared to be a gap). A discontinuity of any size therefore costs no memory: it is served as synthesized gaps between the two stored elements that surround it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
int
|
GPS start time of queue, in nanoseconds. |
None
|
stride
|
int
|
Time step for elements in the queue, in nanoseconds. |
required |
timeout
|
int
|
Timeout for elements in the queue, in nanoseconds. |
required |
Source code in arrakis/mux.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
__len__ ¶
__len__()
Number of buffered real elements (gap spans are implicit).
Source code in arrakis/mux.py
155 156 157 | |
drain_until ¶
drain_until(target_time)
Advance the cursor so serving resumes at or after target_time.
Source code in arrakis/mux.py
350 351 352 353 354 355 356 357 358 359 360 361 | |
front_time ¶
front_time()
Return the next timestamp to be served, or None if nothing is known.
Source code in arrakis/mux.py
343 344 345 346 347 348 | |
next_element_time ¶
next_element_time()
Return the timestamp of the oldest buffered element, or None.
Unlike :meth:front_time this ignores gap spans: it reports
where the next real element is, however far ahead.
Source code in arrakis/mux.py
332 333 334 335 336 337 338 339 340 341 | |
pull ¶
pull(duration=None, *, update_timeout=True)
Drain the queue.
Gaps are represented by None elements, synthesized on the fly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
int
|
Duration to extract, in nanoseconds. If the specified duration is not available, no elements will be returned. If not specified, the known span will be drained. |
None
|
update_timeout
|
bool
|
Whether to trigger timeout gap-filling before pulling. Default is True. Set to False when the caller has already updated timeouts (e.g. BlockMuxStream.pull()). |
True
|
Yields:
| Type | Description |
|---|---|
tuple[time, element]
|
The element from the queue and it's associated timestamp. |
Source code in arrakis/mux.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
push ¶
push(time, element, on_drop=ONDROP_DEFAULT)
Push an element into the queue.
The time being pushed into the queue must be a multiple of the time stride specified at initialization of the queue.
If the time associated with the pushed element is older than the queue's horizon (already served or declared gap), the element will be dropped and this operation will be a no-op.
Pushing None declares the span up to time to be a gap
without storing anything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
int
|
GPS time associated with the element, in nanoseconds |
required |
element
|
Any
|
element being pushed into the queue. |
required |
on_drop
|
str
|
Per-event behavior when the item is dropped as too old (e.g. it arrived after the timeout declared its span a gap, or it is a duplicate). Options are 'ignore', 'raise', or 'warn'. Default is 'ignore': drops are expected under the latency contract, and are always counted and summarized in the log at most once per DROP_LOG_INTERVAL regardless of this policy. |
ONDROP_DEFAULT
|
Source code in arrakis/mux.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
ready ¶
ready(duration, *, update_timeout=True)
Check if queue holds duration worth of elements
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
int
|
Duration to check for, in nanoseconds. |
required |
update_timeout
|
bool
|
Whether to trigger timeout gap-filling before checking. Default is True. Set to False when the caller has already updated timeouts (e.g. BlockMuxStream.ready()). |
True
|
Returns:
| Type | Description |
|---|---|
int or None
|
Returns either the number of elements that span duration, or None if the known span does not cover duration. |
Source code in arrakis/mux.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |