summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kraft <george.kraft@calxeda.com>2012-09-14 13:51:52 -0500
committerGeorge Kraft <george.kraft@calxeda.com>2012-09-14 13:51:52 -0500
commitc3ef914d3afab7d983c8ccfb9d4c1b8dbeca9c71 (patch)
tree484cbcbd31b4185b8a2a9de0abff919beb861b96
parentdaad0761825c24d6b0f85e46c48303b554e80b81 (diff)
downloadcxmanage-c3ef914d3afab7d983c8ccfb9d4c1b8dbeca9c71.tar.gz
CXMAN-91: Print results and errors on keyboard interrupt
If a command is aborted by keyboard interrupt, we can at least print the results/errors of the nodes that completed.
-rw-r--r--cxmanage/controller.py40
1 files changed, 26 insertions, 14 deletions
diff --git a/cxmanage/controller.py b/cxmanage/controller.py
index d80db61..701e9de 100644
--- a/cxmanage/controller.py
+++ b/cxmanage/controller.py
@@ -601,9 +601,27 @@ class Controller:
if self.verbosity == 1:
indicator.start()
- for target in targets:
- # Wait while we have too many running threads
- while len(threads) >= self.max_threads:
+ try:
+ for target in targets:
+ # Wait while we have too many running threads
+ while len(threads) >= self.max_threads:
+ time.sleep(0.001)
+ for thread in threads:
+ if not thread.is_alive():
+ threads.remove(thread)
+ if thread.error == None:
+ results[thread.target.address] = thread.result
+ else:
+ errors[thread.target.address] = thread.error
+ break
+
+ # Start the new thread
+ thread = ControllerCommandThread(target, name, args)
+ thread.start()
+ threads.add(thread)
+
+ # Join with any remaining threads
+ while len(threads) > 0:
time.sleep(0.001)
for thread in threads:
if not thread.is_alive():
@@ -613,23 +631,17 @@ class Controller:
else:
errors[thread.target.address] = thread.error
break
-
- # Start the new thread
- thread = ControllerCommandThread(target, name, args)
- thread.start()
- threads.add(thread)
-
- # Join with any remaining threads
- while len(threads) > 0:
- time.sleep(0.001)
+ except KeyboardInterrupt:
+ retries = 0
for thread in threads:
if not thread.is_alive():
- threads.remove(thread)
if thread.error == None:
results[thread.target.address] = thread.result
else:
errors[thread.target.address] = thread.error
- break
+ for target in targets:
+ if not (target.address in errors or target.address in results):
+ errors[target.address] = "Aborted by keyboard interrupt"
# Stop indicator
if self.verbosity == 1: