summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-22 13:58:04 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-22 13:58:04 -0400
commit831435c445803da76a6e46061417c6708bbfa9d7 (patch)
tree74ebb75d09f91445fc794c119027f416e259a8f1 /examples
parent097c065b740e1f03ad960cb8ec79666d045e1286 (diff)
downloadcmd2-git-831435c445803da76a6e46061417c6708bbfa9d7.tar.gz
Recreating the thread in preloop to support multiple calls of cmdloop
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/async_printing.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/examples/async_printing.py b/examples/async_printing.py
index 69880ee7..981d39e3 100755
--- a/examples/async_printing.py
+++ b/examples/async_printing.py
@@ -84,7 +84,7 @@ class AlerterApp(cmd2.Cmd):
# The thread that will asynchronously alert the user of events
self._stop_thread = False
- self._alerter_thread = threading.Thread(name='alerter', target=self._alerter_thread_func)
+ self._alerter_thread = threading.Thread()
# Create some hooks to handle the starting and stopping of our thread
self.register_preloop_hook(self._preloop_hook)
@@ -96,6 +96,8 @@ class AlerterApp(cmd2.Cmd):
# This function runs after cmdloop() locks _terminal_lock, which will be locked until the prompt appears.
# Therefore it is safe to start our thread since there is no risk of it alerting before the prompt is displayed.
self._stop_thread = False
+
+ self._alerter_thread = threading.Thread(name='alerter', target=self._alerter_thread_func)
self._alerter_thread.start()
def _postloop_hook(self) -> None: