Browse Source

Clean up the command handling loop

The try blocks now only protect the code they need to, which is a Good
Thing™.
Clara Hobbs 6 years ago
parent
commit
2b025c2a61
1 changed files with 12 additions and 7 deletions
  1. 12
    7
      kayleevc/kaylee.py

+ 12
- 7
kayleevc/kaylee.py View File

159
 
159
 
160
         # Give the command to the handlers that want it
160
         # Give the command to the handlers that want it
161
         while True:
161
         while True:
162
+            # Get information about the handler
162
             try:
163
             try:
163
-                # Get information about the handler
164
                 info = confidence_heap.get_nowait()
164
                 info = confidence_heap.get_nowait()
165
-                handler = info[0]
166
-                plugin = info[2]
167
-                # Handle the command
168
-                handler(self.plugin_tts)
169
-                self._log_history(plugin, text)
170
-                break
171
             except queue.Empty:
165
             except queue.Empty:
166
+                # If the queue is empty, we have nothing else to try, so break
172
                 break
167
                 break
168
+            handler = info[0]
169
+            plugin = info[2]
170
+
171
+            # Handle the command
172
+            try:
173
+                handler(self.plugin_tts)
173
             except kayleevc.plugins.HandlerFailure:
174
             except kayleevc.plugins.HandlerFailure:
174
                 # If the handler failed, keep trying
175
                 # If the handler failed, keep trying
175
                 continue
176
                 continue
177
+            else:
178
+                # If the handler succeeded, log it and break
179
+                self._log_history(plugin, text)
180
+                break
176
 
181
 
177
         self._stop_ui(text)
182
         self._stop_ui(text)
178
 
183
 

Loading…
Cancel
Save