def pre_setup_plugins(): """Loads plugins and calls the pre init hooks If twisted has been imported by a plugin, the gtk2reactor is installed """ # load all plugins specified in the RAFCON_PLUGIN_PATH plugins.load_plugins() # check if twisted is imported and if so, install the required reactor if reactor_required(): install_reactor() plugins.run_pre_inits()
def start_client(interacting_function, queue_dict): from rafcon.gui.config import global_gui_config import os from rafcon.gui.controllers.main_window import MainWindowController from rafcon.gui.views.main_window import MainWindowView import rafcon.gui.singleton as gui_singletons from rafcon.gui.runtime_config import global_runtime_config from rafcon.gui.start import signal_handler import rafcon from rafcon.utils import log from rafcon.utils import plugins from rafcon.core.config import global_config from rafcon.core.storage import storage as global_storage from rafcon.core.state_machine import StateMachine from rafcon.core.states.hierarchy_state import HierarchyState import rafcon.core.singleton as core_singletons from rafcon.core.start import setup_environment # load all plugins specified in the RAFCON_PLUGIN_PATH plugins.load_plugins() import testing_utils # check if twisted is imported if "twisted" in sys.modules.keys(): from twisted.internet import gtk2reactor # needed for glib.idle_add, and signals gtk2reactor.install() from twisted.internet import reactor else: print "Twisted not imported! Thus the gkt2reatcor is not installed!" exit() plugins.run_pre_inits() setup_logger() logger = log.get_logger("start") logger.info("RAFCON launcher") setup_environment() signal.signal(signal.SIGINT, signal_handler) global_config.load(path=os.path.dirname(os.path.abspath(__file__))) global_gui_config.load(path=os.path.dirname(os.path.abspath(__file__))) global_runtime_config.load(path=os.path.dirname(os.path.abspath(__file__))) setup_config = dict() setup_config["net_config_path"] = os.path.abspath(path=os.path.join( os.path.dirname(os.path.abspath(__file__)), "client")) # Initialize library core_singletons.library_manager.initialize() # Create the GUI main_window_view = MainWindowView() state_machine = global_storage.load_state_machine_from_path( testing_utils.get_test_sm_path( os.path.join("unit_test_state_machines", "99_bottles_of_beer_monitoring"))) sm_id = rafcon.core.singleton.state_machine_manager.add_state_machine( state_machine) rafcon.core.singleton.state_machine_manager.active_state_machine_id = sm_id sm_manager_model = gui_singletons.state_machine_manager_model main_window_controller = MainWindowController(sm_manager_model, main_window_view) plugins.run_post_inits(setup_config) import threading # this is not recognized by pycharm as the module is loaded in plugins.load_plugins() from monitoring.monitoring_manager import global_monitoring_manager interacting_thread = threading.Thread( target=interacting_function, args=[main_window_controller, global_monitoring_manager, queue_dict]) testing_utils.wait_for_gui() interacting_thread.start() # check if twisted is imported if "twisted" in sys.modules.keys(): reactor.run() else: logger.error( "Client: Twisted is not in sys.modules or twisted is not working! Exiting program ... !" ) os._exit(0) logger.info("Joined root state") # If there is a running state-machine, wait for it to be finished before exiting sm = core_singletons.state_machine_manager.get_active_state_machine() if sm: sm.root_state.join() logger.info("Exiting ...") # this is a ugly process shutdown method but works if gtk or twisted process are still blocking os._exit(0)
def start_server(interacting_function, queue_dict): import sys import os import rafcon from rafcon.utils import log from rafcon.utils import plugins from rafcon.core.config import global_config import rafcon.core.singleton as core_singletons from rafcon.core.storage import storage as global_storage # needed for yaml parsing from rafcon.core.states.hierarchy_state import HierarchyState from rafcon.core.states.execution_state import ExecutionState from rafcon.core.states.preemptive_concurrency_state import PreemptiveConcurrencyState from rafcon.core.states.barrier_concurrency_state import BarrierConcurrencyState from rafcon.core.start import signal_handler, register_signal_handlers register_signal_handlers(signal_handler) logger = log.get_logger("start-no-gui") logger.info("initialize RAFCON ... ") plugins.load_plugins() plugins.run_pre_inits() global_config.load(path=os.path.dirname(os.path.abspath(__file__))) # Initialize libraries core_singletons.library_manager.initialize() from tests import utils as testing_utils state_machine = global_storage.load_state_machine_from_path( testing_utils.get_test_sm_path(os.path.join("unit_test_state_machines", "99_bottles_of_beer_monitoring"))) sm_id = rafcon.core.singleton.state_machine_manager.add_state_machine(state_machine) sm_thread = threading.Thread(target=check_for_sm_finished, args=[state_machine, ]) sm_thread.start() setup_config = dict() setup_config["net_config_path"] = os.path.abspath(path=os.path.join(os.path.dirname(os.path.abspath(__file__)), "server")) plugins.run_post_inits(setup_config) if "twisted" in sys.modules: print("################# twisted found #######################") interacting_thread = threading.Thread(target=interacting_function, args=[queue_dict, sm_id]) interacting_thread.start() from twisted.internet import reactor reactor.run() else: logger.error("Server: Twisted is not in sys.modules or twisted is not working! Exiting program ... !") import os os._exit(0) state_machine.root_state.join() rafcon.core.singleton.state_machine_execution_engine.stop() logger.info("State machine execution finished!")
def pre_setup_plugins(): """Loads plugins and calls the pre init hooks """ plugins.load_plugins() plugins.run_pre_inits()