braket.jobs.logs module

class braket.jobs.logs.ColorWrap(force: bool = False)[source]

Bases: object

A callable that prints text in a different color depending on the instance. Up to 5 if the standard output is a terminal or a Jupyter notebook cell.

Initialize a ColorWrap.

Parameters:

force (bool) – If True, the render output is colorized wherever the output is. Default: False.

class braket.jobs.logs.Position(timestamp, skip)

Bases: tuple

Create new instance of Position(timestamp, skip)

skip

Alias for field number 1

timestamp

Alias for field number 0

braket.jobs.logs.multi_stream_iter(aws_session: AwsSession, log_group: str, streams: list[str], positions: dict[str, Position]) Generator[tuple[int, dict]][source]

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.

Parameters:
  • aws_session (AwsSession) – The AwsSession for interfacing with CloudWatch.

  • log_group (str) – The name of the log group.

  • streams (list[str]) – A list of the log stream names. The the stream number is the position of the stream in this list.

  • positions (dict[str, Position]) – A list of (timestamp, skip) pairs which represent the last record read from each stream.

Yields:

Generator[tuple[int, dict]] – A tuple of (stream number, cloudwatch log event).

braket.jobs.logs.log_stream(aws_session: AwsSession, log_group: str, stream_name: str, start_time: int = 0, skip: int = 0) Generator[dict][source]

A generator for log items in a single stream. This yields all the items that are available at the current moment.

Parameters:
  • aws_session (AwsSession) – The AwsSession for interfacing with CloudWatch.

  • log_group (str) – The name of the log group.

  • stream_name (str) – The name of the specific stream.

  • start_time (int) – The time stamp value to start reading the logs from. Default: 0.

  • skip (int) – The number of log entries to skip at the start. Default: 0 (This is for when there are multiple entries at the same timestamp.)

Yields:

Generator[dict] – A CloudWatch log event with the following key-value pairs: ‘timestamp’ (int): The time of the event. ‘message’ (str): The log event data. ‘ingestionTime’ (int): The time the event was ingested.

braket.jobs.logs.flush_log_streams(aws_session: AwsSession, log_group: str, stream_prefix: str, stream_names: list[str], positions: dict[str, Position], stream_count: int, has_streams: bool, color_wrap: ColorWrap, state: list[str], queue_position: str | None = None) bool[source]

Flushes log streams to stdout.

Parameters:
  • aws_session (AwsSession) – The AwsSession for interfacing with CloudWatch.

  • log_group (str) – The name of the log group.

  • stream_prefix (str) – The prefix for log streams to flush.

  • stream_names (list[str]) – A list of the log stream names. The position of the stream in this list is the stream number. If incomplete, the function will check for remaining streams and mutate this list to add stream names when available, up to the stream_count limit.

  • positions (dict[str, Position]) – A dict mapping stream numbers to (timestamp, skip) pairs which represent the last record read from each stream. The function will update this list after being called to represent the new last record read from each stream.

  • stream_count (int) – The number of streams expected.

  • has_streams (bool) – Whether the function has already been called once all streams have been found. This value is possibly updated and returned at the end of execution.

  • color_wrap (ColorWrap) – An instance of ColorWrap to potentially color-wrap print statements from different streams.

  • state (list[str]) – The previous and current state of the job.

  • queue_position (Optional[str]) – The current queue position. This is not passed in if the job is ran with quiet=True

Raises:

Exception – Any exception found besides a ResourceNotFoundException.

Returns:

bool – Returns ‘True’ if any streams have been flushed.