def gtk_call_once(func, *args): """Wrapper for GLib.idle_add call that ensures the func is called only once. """ def wrap(args): func(*args) return False run_in_loop(wrap, args)
def gtk_call_once(func, *args): """Wrapper for GLib.idle_add call that ensures the func is called only once. """ def wrap(args): func(*args) return False run_in_loop(wrap, args)
def run(self): """Run the boss's loop.""" log.debug("Gather the modules.") self._module_manager.add_default_modules() self._module_manager.add_addon_modules() log.debug("Schedule publishing.") run_in_loop(self.publish) log.debug("Schedule startup of modules.") run_in_loop(self._module_manager.start_modules) log.info("starting mainloop") self._loop.run()
def gtk_batch_map(action, items, args=(), pre_func=None, batch_size=1): """ Function that maps an action on items in a way that makes the action run in the main thread, but without blocking the main thread for a noticeable time. If a pre-processing function is given it is mapped on the items first before the action happens in the main thread. .. DANGER:: MUST NOT BE CALLED NOR WAITED FOR FROM THE MAIN THREAD. :param action: any action that has to be done on the items in the main thread :type action: (action_item, \\*args) -> None :param items: an iterable of items that the action should be mapped on :type items: iterable :param args: additional arguments passed to the action function :type args: tuple :param pre_func: a function that is mapped on the items before they are passed to the action function :type pre_func: item -> action_item :param batch_size: how many items should be processed in one run in the main loop :raise AssertionError: if called from the main thread :return: None """ assert (not threadMgr.in_main_thread()) def preprocess(queue_instance): if pre_func: for item in items: queue_instance.put(pre_func(item)) else: for item in items: queue_instance.put(item) queue_instance.put(TERMINATOR) def process_one_batch(arguments): (queue_instance, action, done_event) = arguments tstamp_start = time.time() tstamp = time.time() # process as many batches as user shouldn't notice while tstamp - tstamp_start < NOTICEABLE_FREEZE: for _i in range(batch_size): try: action_item = queue_instance.get_nowait() if action_item is TERMINATOR: # all items processed, tell we are finished and return done_event.set() return False else: # run action on the item action(action_item, *args) except queue.Empty: # empty queue_instance, reschedule to run later return True tstamp = time.time() # out of time but something left, reschedule to run again later return True item_queue_instance = queue.Queue() done_event = threading.Event() # we don't want to log the whole list, type and address is enough log.debug("Starting applying %s on %s", action, object.__repr__(items)) # start a thread putting preprocessed items into the queue_instance threadMgr.add( AnacondaThread(prefix="AnaGtkBatchPre", target=preprocess, args=(item_queue_instance, ))) run_in_loop(process_one_batch, (item_queue_instance, action, done_event)) done_event.wait() log.debug("Finished applying %s on %s", action, object.__repr__(items))
def run(self): """Run the module's loop.""" log.debug("Schedule publishing.") run_in_loop(self.publish) log.debug("Start the loop.") self._loop.run()
def handleException(self, dump_info): """ Our own handleException method doing some additional stuff before calling the original python-meh's one. :type dump_info: an instance of the meh.DumpInfo class :see: python-meh's ExceptionHandler.handleException """ log.debug("running handleException") exception_lines = traceback.format_exception(*dump_info.exc_info) log.critical("\n".join(exception_lines)) ty = dump_info.exc_info.type value = dump_info.exc_info.value try: gi.require_version("Gtk", "3.0") from gi.repository import Gtk # XXX: Gtk stopped raising RuntimeError if it fails to # initialize. Horay! But will it stay like this? Let's be # cautious and raise the exception on our own to work in both # cases initialized = Gtk.init_check(None)[0] if not initialized: raise RuntimeError() # Attempt to grab the GUI initializing lock, do not block if not self._gui_lock.acquire(False): # the graphical interface is running, don't crash it by # running another one potentially from a different thread log.debug( "Gtk running, queuing exception handler to the main loop") run_in_loop(self._main_loop_handleException, dump_info) else: log.debug( "Gtk not running, starting Gtk and running exception handler in it" ) self._main_loop_handleException(dump_info) except (RuntimeError, ImportError, ValueError): log.debug("Gtk cannot be initialized") # X not running (Gtk cannot be initialized) if threadMgr.in_main_thread(): log.debug("In the main thread, running exception handler") if issubclass(ty, NonInteractiveError) or not self._interactive: if issubclass(ty, NonInteractiveError): cmdline_error_msg = _( "\nThe installation was stopped due to an " "error which occurred while running in " "non-interactive cmdline mode. Since there " "cannot be any questions in cmdline mode, edit " "your kickstart file and retry installation. " "\nThe exact error message is: \n\n%s. \n\nThe " "installer will now terminate.") % str(value) else: cmdline_error_msg = _( "\nRunning in cmdline mode, no interactive " "debugging allowed.\nThe exact error message is: " "\n\n%s.\n\nThe installer will now terminate." ) % str(value) # since there is no UI in cmdline mode and it is completely # non-interactive, we can't show a message window asking the user # to acknowledge the error; instead, print the error out and sleep # for a few seconds before exiting the installer print(cmdline_error_msg) time.sleep(180) sys.exit(1) else: print("\nAn unknown error has occured, look at the " "/tmp/anaconda-tb* file(s) for more details") # in the main thread, run exception handler self._main_loop_handleException(dump_info) else: log.debug( "In a non-main thread, sending a message with exception data" ) # not in the main thread, just send message with exception # data and let message handler run the exception handler in # the main thread exc_info = dump_info.exc_info # new Simpleline package is now used in TUI. Look if Simpleline is # initialized or if this is some fallback from GTK or other stuff. if App.is_initialized(): # if Simpleline is initialized enqueue exception there loop = App.get_event_loop() loop.enqueue_signal( ExceptionSignal(App.get_scheduler(), exception_info=exc_info)) else: hubQ.send_exception( (exc_info.type, exc_info.value, exc_info.stack))
def run(self): """Run the boss's loop.""" log.debug("Schedule publishing.") run_in_loop(self.publish) log.info("Start the main loop.") self._loop.run()
def run(self): """Run the module's loop.""" log.debug("Schedule publishing.") run_in_loop(self.publish) log.debug("Start the loop.") self._loop.run()
def handleException(self, dump_info): """ Our own handleException method doing some additional stuff before calling the original python-meh's one. :type dump_info: an instance of the meh.DumpInfo class :see: python-meh's ExceptionHandler.handleException """ log.debug("running handleException") exception_lines = traceback.format_exception(*dump_info.exc_info) log.critical("\n".join(exception_lines)) ty = dump_info.exc_info.type value = dump_info.exc_info.value try: gi.require_version("Gtk", "3.0") from gi.repository import Gtk # XXX: Gtk stopped raising RuntimeError if it fails to # initialize. Horay! But will it stay like this? Let's be # cautious and raise the exception on our own to work in both # cases initialized = Gtk.init_check(None)[0] if not initialized: raise RuntimeError() # Attempt to grab the GUI initializing lock, do not block if not self._gui_lock.acquire(False): # the graphical interface is running, don't crash it by # running another one potentially from a different thread log.debug("Gtk running, queuing exception handler to the main loop") run_in_loop(self._main_loop_handleException, dump_info) else: log.debug("Gtk not running, starting Gtk and running exception handler in it") self._main_loop_handleException(dump_info) except (RuntimeError, ImportError, ValueError): log.debug("Gtk cannot be initialized") # X not running (Gtk cannot be initialized) if threadMgr.in_main_thread(): log.debug("In the main thread, running exception handler") if issubclass(ty, NonInteractiveError) or not self._interactive: if issubclass(ty, NonInteractiveError): cmdline_error_msg = _("\nThe installation was stopped due to an " "error which occurred while running in " "non-interactive cmdline mode. Since there " "cannot be any questions in cmdline mode, edit " "your kickstart file and retry installation. " "\nThe exact error message is: \n\n%s. \n\nThe " "installer will now terminate.") % str(value) else: cmdline_error_msg = _("\nRunning in cmdline mode, no interactive " "debugging allowed.\nThe exact error message is: " "\n\n%s.\n\nThe installer will now terminate." ) % str(value) # since there is no UI in cmdline mode and it is completely # non-interactive, we can't show a message window asking the user # to acknowledge the error; instead, print the error out and sleep # for a few seconds before exiting the installer print(cmdline_error_msg) time.sleep(180) sys.exit(1) else: print("\nAn unknown error has occured, look at the " "/tmp/anaconda-tb* file(s) for more details") # in the main thread, run exception handler self._main_loop_handleException(dump_info) else: log.debug("In a non-main thread, sending a message with exception data") # not in the main thread, just send message with exception # data and let message handler run the exception handler in # the main thread exc_info = dump_info.exc_info # new Simpleline package is now used in TUI. Look if Simpleline is # initialized or if this is some fallback from GTK or other stuff. if App.is_initialized(): # if Simpleline is initialized enqueue exception there loop = App.get_event_loop() loop.enqueue_signal(ExceptionSignal(App.get_scheduler(), exception_info=exc_info)) else: hubQ.send_exception((exc_info.type, exc_info.value, exc_info.stack))
def run(self): """Run the loop.""" run_in_loop(self._connect_to_hostname_service_once_available) super().run()
def gtk_batch_map(action, items, args=(), pre_func=None, batch_size=1): """ Function that maps an action on items in a way that makes the action run in the main thread, but without blocking the main thread for a noticeable time. If a pre-processing function is given it is mapped on the items first before the action happens in the main thread. .. DANGER:: MUST NOT BE CALLED NOR WAITED FOR FROM THE MAIN THREAD. :param action: any action that has to be done on the items in the main thread :type action: (action_item, \\*args) -> None :param items: an iterable of items that the action should be mapped on :type items: iterable :param args: additional arguments passed to the action function :type args: tuple :param pre_func: a function that is mapped on the items before they are passed to the action function :type pre_func: item -> action_item :param batch_size: how many items should be processed in one run in the main loop :raise AssertionError: if called from the main thread :return: None """ assert(not threadMgr.in_main_thread()) def preprocess(queue_instance): if pre_func: for item in items: queue_instance.put(pre_func(item)) else: for item in items: queue_instance.put(item) queue_instance.put(TERMINATOR) def process_one_batch(arguments): (queue_instance, action, done_event) = arguments tstamp_start = time.time() tstamp = time.time() # process as many batches as user shouldn't notice while tstamp - tstamp_start < NOTICEABLE_FREEZE: for _i in range(batch_size): try: action_item = queue_instance.get_nowait() if action_item is TERMINATOR: # all items processed, tell we are finished and return done_event.set() return False else: # run action on the item action(action_item, *args) except queue.Empty: # empty queue_instance, reschedule to run later return True tstamp = time.time() # out of time but something left, reschedule to run again later return True item_queue_instance = queue.Queue() done_event = threading.Event() # we don't want to log the whole list, type and address is enough log.debug("Starting applying %s on %s", action, object.__repr__(items)) # start a thread putting preprocessed items into the queue_instance threadMgr.add(AnacondaThread(prefix="AnaGtkBatchPre", target=preprocess, args=(item_queue_instance,))) run_in_loop(process_one_batch, (item_queue_instance, action, done_event)) done_event.wait() log.debug("Finished applying %s on %s", action, object.__repr__(items))
def run(self): """Run the boss's loop.""" log.debug("Schedule publishing.") run_in_loop(self.publish) log.info("Start the main loop.") self._loop.run()