Remove unnecessary doctest comments from test/get_curve.py
[hooke.git] / hooke / engine.py
index b4381298178f59723b540cfc901a7968ac93e1c1..75f74fe2a48908ee5787559b80649a8b194200d0 100644 (file)
@@ -21,6 +21,7 @@
 """
 
 import logging
+from Queue import Queue, Empty
 
 from .command import NullQueue
 
@@ -35,10 +36,10 @@ class CloseEngine (QueueMessage):
 
 
 class CommandMessage (QueueMessage):
-    """A message storing a command to run, `command` should be a
-    :class:`hooke.command.Command` instance, and `arguments` should be
-    a :class:`dict` with `argname` keys and `value` values to be
-    passed to the command.
+    """A message storing a command to run, `command` should be the
+    name of a :class:`hooke.command.Command` instance, and `arguments`
+    should be a :class:`dict` with `argname` keys and `value` values
+    to be passed to the command.
     """
     def __init__(self, command, arguments=None):
         self.command = command
@@ -72,9 +73,11 @@ class CommandEngine (object):
                     'engine closing, placed hooke instance in return queue')
                 break
             assert isinstance(msg, CommandMessage), type(msg)
-            log.debug('engine running %s' % msg.command.name)
-            msg.command.run(hooke, ui_to_command_queue, command_to_ui_queue,
-                            **msg.arguments)
+            log.debug('engine running %s with %s'
+                      % (msg.command, msg.arguments))
+            cmd = hooke.command_by_name[msg.command]
+            cmd.run(hooke, ui_to_command_queue, command_to_ui_queue,
+                    **msg.arguments)
 
     def run_command(self, hooke, command, arguments):
         """Internal command execution.
@@ -86,4 +89,15 @@ class CommandEngine (object):
         communication queues, so make sure they will not need user
         interaction.
         """
-        command.run(hooke, NullQueue(), NullQueue(), arguments)
+        log = logging.getLogger('hooke')
+        log.debug('engine running internal %s with %s'
+                  % (command, arguments))
+        cmd = hooke.command_by_name[command]
+        outqueue = Queue()
+        cmd.run(hooke, NullQueue(), outqueue, **arguments)
+        while True:
+            try:
+                msg = outqueue.get(block=False)
+            except Empty:
+                break
+            log.debug('engine message from %s (%s): %s' % (command, type(msg), msg))