MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / _get_alerts

Method _get_alerts

examples/async_printing.py:78–104  ·  view source on GitHub ↗

Reports alerts :return: the list of alerts.

(self)

Source from the content-addressed store, hash-verified

76 print("The alert thread is already stopped")
77
78 def _get_alerts(self) -> list[str]:
79 """Reports alerts
80 :return: the list of alerts.
81 """
82 cur_time = time.monotonic()
83 if cur_time < self._next_alert_time:
84 return []
85
86 alerts = []
87
88 if self._alert_count < len(ALERTS):
89 alerts.append(ALERTS[self._alert_count])
90 self._alert_count += 1
91 self._next_alert_time = cur_time + 4
92
93 else:
94 rand_num = random.randint(1, 20)
95 if rand_num > 2:
96 return []
97
98 for _ in range(rand_num):
99 self._alert_count += 1
100 alerts.append(f"Alert {self._alert_count}")
101
102 self._next_alert_time = 0
103
104 return alerts
105
106 def _build_alert_str(self) -> str:
107 """Combines alerts into one string that can be printed to the terminal

Callers 1

_build_alert_strMethod · 0.95

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected