then runs the UI, rejoining the `CommandEngine` process after
the UI exits.
"""
- ui_to_command = multiprocessing.Queue()
- command_to_ui = multiprocessing.Queue()
- command = multiprocessing.Process(
- target=self.command.run, args=(self, ui_to_command, command_to_ui))
- command.start()
+ ui_to_command,command_to_ui,command = self._setup_run()
try:
self.ui.run(self.commands, ui_to_command, command_to_ui)
finally:
- ui_to_command.put(ui.CloseEngine())
- command.join()
+ self._cleanup_command(ui_to_command, command_to_ui, command)
def run_lines(self, lines):
"""Run the pre-set commands `lines` with the "command line" UI.
equivalent to :meth:'.run'.
"""
cmdline = ui.load_ui(self.config, 'command line')
- ui_to_command = multiprocessing.Queue()
- command_to_ui = multiprocessing.Queue()
- command = multiprocessing.Process(
- target=self.command.run, args=(self, ui_to_command, command_to_ui))
- command.start()
+ ui_to_command,command_to_ui,command = self._setup_run()
try:
cmdline.run_lines(
self.commands, ui_to_command, command_to_ui, lines)
finally:
- ui_to_command.put(ui.CloseEngine())
- command.join()
+ self._cleanup_command(ui_to_command, command_to_ui, command)
+
+ def _setup_run(self):
+ ui_to_command = multiprocessing.Queue()
+ command_to_ui = multiprocessing.Queue()
+ command = multiprocessing.Process(name='command engine',
+ target=self.command.run, args=(self, ui_to_command, command_to_ui))
+ command.start()
+ return (ui_to_command, command_to_ui, command)
+
+ def _cleanup_run(self, ui_to_command, command_to_ui, command):
+ ui_to_command.put(ui.CloseEngine())
+ command.join()
+
def main():
p = optparse.OptionParser()