Commits

Rodrigo Bistolfi  committed 7c0cb28

Execute Controller.process() in another thread

  • Participants
  • Parent commits 5c18cf4
  • Branches advanced_autopartition

Comments (0)

Files changed (1)

File vinstall/core/wizard.py

 import Queue
 import sys
 from inspect import isgeneratorfunction
+from futures import ThreadPoolExecutor
 from .command import ProcessingFacade
 
 
         self.current_controller = None
         self.current_render = None
         self.commands = []
+        self.pool = ThreadPoolExecutor(5)
 
     def process_state(self, controller):
         "Process the current state of the wizard"
 
     def run_controller(self):
         "Execute tasks specified by the controller"
-        process_method = getattr(self.current_controller, "process", None)
         args = self.current_render.get_user_input()
+        self.handle_process_method(args)
+
+    def handle_process_method(self, args):
+        process_method = getattr(self.current_controller, "process", None)
+
         if process_method:
-            self.execute(process_method, args, {})
+            #self.current_render.main_window.disable_buttons()
+
+            def callback(f=None):
+                self.handle_command_method(args)
+                #self.current_render.main_window.enable_buttons()
+                self._next()
+
+            future = self.pool.submit(lambda: self.execute(process_method, 
+                args, {}))
+            future.add_done_callback(callback)
+        else:
+            self.handle_command_method(args)
+            self._next()
+
+    def handle_command_method(self, args):
         command_method = getattr(self.current_controller, "command", None)
         if command_method:
             self.commands.append((command_method, args))
     def next(self, *_):
         "Jump to the next state of the application"
         self.run_controller()
+
+    def _next(self):
         next_controller = self.current_controller.next()
         if next_controller:
             instance = self.factory.make_controller_instance(next_controller)