Skip to content

Commit f6b6b41

Browse files
committed
Killing the alert processing thread.
1 parent 72789b3 commit f6b6b41

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cmd2/cmd2.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,7 +3360,7 @@ def _process_alerts(self) -> None:
33603360
while not self._alerter_shutdown.is_set():
33613361
try:
33623362
# Wait for an alert
3363-
alert = self.alert_queue.get(timeout=0.5)
3363+
alert = self.alert_queue.get(timeout=0.1)
33643364

33653365
# Block if not at a prompt
33663366
while not self._alerter_gate.is_set():
@@ -3456,7 +3456,17 @@ def _cmdloop(self) -> None:
34563456
# Run the command along with all associated pre and post hooks
34573457
stop = self.onecmd_plus_hooks(line)
34583458
finally:
3459-
pass
3459+
with self.sigint_protection:
3460+
# Shut down the _process_alerts_thread
3461+
if self._process_alerts_thread is not None and self._process_alerts_thread.is_alive():
3462+
self._alerter_shutdown.set()
3463+
3464+
# Worker is a daemon polling every 0.1s. We join with a 1.0s
3465+
# safety timeout that is highly unlikely to be reached.
3466+
# If it is, the daemon status ensures the OS reaps the
3467+
# thread when the process exits rather than hanging.
3468+
self._process_alerts_thread.join(timeout=1.0)
3469+
self._process_alerts_thread = None
34603470

34613471
#############################################################
34623472
# Parsers and functions for alias command and subcommands

0 commit comments

Comments
 (0)