:class:`hooke.command.Command`\s.
"""
+import logging
+
from .ui import CloseEngine, CommandMessage
+
class CommandEngine (object):
def run(self, hooke, ui_to_command_queue, command_to_ui_queue):
"""Get a :class:`hooke.ui.QueueMessage` from the incoming
`command_to_ui_queue`, at which point the `CommandEngine` will
be ready to receive the next :class:`hooke.ui.QueueMessage`.
"""
+ log = logging.getLogger('hooke')
while True:
+ log.debug('engine waiting for command')
msg = ui_to_command_queue.get()
if isinstance(msg, CloseEngine):
command_to_ui_queue.put(hooke)
+ log.debug(
+ '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)
import multiprocessing
import optparse
import os.path
+import Queue
import unittest
import StringIO
import sys
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