in src/braket/jobs/logs.py [0:0]
def multi_stream_iter(aws_session, log_group, streams, positions):
"""Iterates over the available events coming from a set of log streams.
Log streams are in a single log group interleaving the events from each stream,
so they yield in timestamp order.
Args:
aws_session (AwsSession): The AwsSession for interfacing with CloudWatch.
log_group (str): The name of the log group.
streams (list of str): A list of the log stream names. The the stream number is
the position of the stream in this list.
positions: (list of Positions): A list of (timestamp, skip) pairs which represent
the last record read from each stream.
Yields:
A tuple of (stream number, cloudwatch log event).
"""
event_iters = [
log_stream(aws_session, log_group, s, positions[s].timestamp, positions[s].skip)
for s in streams
]
events = []
for s in event_iters:
try:
events.append(next(s))
except StopIteration:
events.append(None)
while any(events):
i = events.index(min(events, key=lambda x: x["timestamp"] if x else float("inf")))
yield i, events[i]
try:
events[i] = next(event_iters[i])
except StopIteration:
events[i] = None