Fix run cleanup if the UI ends without clearing non-Hooke msgs from the Queue.
[hooke.git] / hooke / hooke.py
index 1923d229c6151bdc241c51f6e4df99dcd047e43d..c2ef159d8bccc4bbbfe5ac5b789ad52ae55132f1 100644 (file)
@@ -59,6 +59,7 @@ import logging.config
 import multiprocessing
 import optparse
 import os.path
+import Queue
 import unittest
 import StringIO
 import sys
@@ -156,9 +157,14 @@ class HookeRunner (object):
         return (ui_to_command, command_to_ui, command)
 
     def _cleanup_run(self, ui_to_command, command_to_ui, command):
+        log = logging.getLogger('hooke')
+        log.debug('cleanup sending CloseEngine')
         ui_to_command.put(ui.CloseEngine())
-        hooke = command_to_ui.get()
-        assert isinstance(hooke, Hooke)
+        hooke = None
+        while not isinstance(hooke, Hooke):
+            log.debug('cleanup waiting for Hooke instance from the engine.')
+            hooke = command_to_ui.get(block=True)
+            log.debug('cleanup got %s instance' % type(hooke))
         command.join()
         return hooke