def stop(self): # NOTE(jkoelker) Stop the idl and event_proxy threads first # letting them finish their current loop. self.is_active = False hub.joinall(self.threads) self._idl.close() super(RemoteOvsdb, self).stop()
def start(self): self.is_active = True self.sock.settimeout(GLOBAL_CONF.socket_timeout) self._threads.append(hub.spawn(self._send_loop)) self._threads.append(hub.spawn(self._recv_loop)) self.server.send_event_to_observers( zserver_event.EventZClientConnected(self)) hub.joinall(self._threads) self.server.send_event_to_observers( zserver_event.EventZClientDisconnected(self))
def serve(self): send_thr = hub.spawn(self._send_loop) # send hello message immediately hello = self.ofproto_parser.OFPHello(self) self.send_msg(hello) echo_thr = hub.spawn(self._echo_request_loop) try: self._recv_loop() finally: hub.kill(send_thr) hub.kill(echo_thr) hub.joinall([send_thr, echo_thr]) self.is_active = False
def main(args=None, prog=None): _parse_user_flags() try: CONF(args=args, prog=prog, project='os_ken', version='osken-manager %s' % version, default_config_files=['/usr/local/etc/os_ken/os_ken.conf']) except cfg.ConfigFilesNotFoundError: CONF(args=args, prog=prog, project='os_ken', version='osken-manager %s' % version) log.init_log() logger = logging.getLogger(__name__) if CONF.enable_debugger: msg = 'debugging is available (--enable-debugger option is turned on)' logger.info(msg) else: hub.patch(thread=True) if CONF.pid_file: with open(CONF.pid_file, 'w') as pid_file: pid_file.write(str(os.getpid())) app_lists = CONF.app_lists + CONF.app # keep old behavior, run ofp if no application is specified. if not app_lists: app_lists = ['os_ken.controller.ofp_handler'] app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = [] services.extend(app_mgr.instantiate_apps(**contexts)) webapp = wsgi.start_service(app_mgr) if webapp: thr = hub.spawn(webapp) services.append(thr) try: hub.joinall(services) except KeyboardInterrupt: logger.debug("Keyboard Interrupt received. " "Closing OSKen application manager...") finally: app_mgr.close()
def run_apps(app_lists): """Run a set of OSKen applications A convenient method to load and instantiate apps. This blocks until all relevant apps stop. """ app_mgr = AppManager.get_instance() app_mgr.load_apps(app_lists) contexts = app_mgr.create_contexts() services = app_mgr.instantiate_apps(**contexts) try: hub.joinall(services) finally: app_mgr.close() for t in services: t.kill() hub.joinall(services) gc.collect()
def _bulk_read_handler(self, ev): results = [] def done(gt, *args, **kwargs): if gt in self.threads: self.threads.remove(gt) results.append(gt.wait()) threads = [] for c in self._clients.values(): gt = hub.spawn(c.read_request_handler, ev, bulk=True) threads.append(gt) self.threads.append(gt) gt.link(done) hub.joinall(threads) rep = event.EventReadReply(None, results) self.reply_to_request(ev, rep)
def start(self): self.is_active = True try: self.sock = create_connection(self.client.zserv_addr) except socket.error as e: self.logger.exception('Cannot connect to Zebra server%s: %s', self.client.zserv_addr, e) self.stop() return None self.sock.settimeout(GLOBAL_CONF.socket_timeout) self.threads.append(hub.spawn(self._send_loop)) self.threads.append(hub.spawn(self._recv_loop)) # Send the following messages at starting connection. # - ZEBRA_HELLO to register route_type # - ZEBRA_ROUTER_ID_ADD to get router_id # - ZEBRA_INTERFACE_ADD to get info for interfaces self.client.send_msg( zebra.ZebraMessage(version=self.client.zserv_ver, body=zebra.ZebraHello( route_type=self.client.route_type, instance=0))) self.client.send_msg( zebra.ZebraMessage(version=self.client.zserv_ver, body=zebra.ZebraRouterIDAdd())) self.client.send_msg( zebra.ZebraMessage(version=self.client.zserv_ver, body=zebra.ZebraInterfaceAdd())) self.client.send_event_to_observers( zclient_event.EventZServConnected(self)) hub.joinall(self.threads) self.client.send_event_to_observers( zclient_event.EventZServDisconnected(self))
def close(self): self.is_active = False if self.link_discovery: self.lldp_event.set() self.link_event.set() hub.joinall(self.threads)
def stop(self): if self.main_thread: hub.kill(self.main_thread) self.is_active = False self._send_event(self._event_stop, None) hub.joinall(self.threads)
def stop(self): super().stop() if self.is_active(): hub.kill(self.thread) hub.joinall([self.thread]) self.thread = None
def cancel(self): if self._thread is None: return self._event.set() hub.joinall([self._thread]) self._thread = None
def stop(self): if self.thread is not None: hub.kill(self.thread) hub.joinall([self.thread]) self.thread = None