def stop_running_tasks(self): log.debug('stopping task') for t in self.background_threads.itervalues(): log.debug('stopping task %s', t) t.terminate() join_threads(self.background_threads.values(), max_wait_time=5) self.background_threads.clear()
def main(config_filename, port_check=True, open_webbrowser=False): from .appstate import GeoBoxState from .defaults import GeoBoxConfig from .lib import log as liblog if config_filename: config = GeoBoxConfig.from_file(config_filename) if not config: sys.exit(1) app_state = GeoBoxState(config) else: app_state = GeoBoxState() liblog.init_logging(app_state) log = logging.getLogger('geobox.app') from .utils import port_used if port_used(app_state.config.get('web', 'port')): log.fatal('Web port %d in use', app_state.config.get('web', 'port')) sys.exit(1) if port_used(app_state.config.get('mapproxy', 'port')): log.fatal('Mapproxy port %d in use', app_state.config.get('mapproxy', 'port')) sys.exit(1) if port_used(app_state.config.get_int('couchdb', 'port')): log.fatal('CouchDB port %s in use', app_state.config.get('couchdb', 'port')) sys.exit(1) factories = [ app_server_thread, couchdb_server_thread, background_process_thread, mapproxy_thread, ] add_default_background_layer(app_state) if sys.platform == 'win32': factories.append(tray_icon_thread) background_threads = [] for factory in factories: log.info('Starting: %s', factory.__doc__ or factory.__name__) t = factory(app_state) t.daemon = True # start as daemon thread so that we can terminate app when # we failed to join thread t.start() background_threads.append(t) # make sure the server for our external tilebox is running app_state.tilebox.restart() if open_webbrowser: open_webbrowser_in_background( '127.0.0.1', app_state.config.get('web', 'port')) try: # wait till someone calls app_state.shutdown_app() while not app_state.wait_for_app_shutdown(timeout=60): # waiting for event without timeout will intercept # KeyboardInterrupts pass except (KeyboardInterrupt, SystemExit): app_state.shutdown_app() log.info('Shutting down') for t in background_threads: t.shutdown() from geobox.utils import join_threads join_threads(background_threads, max_wait_time=10) app_state.cleanup() log.info('Terminating')
def main(config_filename, port_check=True, open_webbrowser=False): from .appstate import GeoBoxState from .defaults import GeoBoxConfig from .lib import log as liblog if config_filename: config = GeoBoxConfig.from_file(config_filename) if not config: sys.exit(1) app_state = GeoBoxState(config) else: app_state = GeoBoxState() liblog.init_logging(app_state) log = logging.getLogger("geobox.app") from .utils import port_used if port_used(app_state.config.get("web", "port")): log.fatal("Web port %d in use", app_state.config.get("web", "port")) sys.exit(1) if port_used(app_state.config.get("mapproxy", "port")): log.fatal("Mapproxy port %d in use", app_state.config.get("mapproxy", "port")) sys.exit(1) if port_used(app_state.config.get_int("couchdb", "port")): log.fatal("CouchDB port %s in use", app_state.config.get("couchdb", "port")) sys.exit(1) factories = [app_server_thread, couchdb_server_thread, background_process_thread, mapproxy_thread] add_default_background_layer(app_state) if sys.platform == "win32": factories.append(tray_icon_thread) background_threads = [] for factory in factories: log.info("Starting: %s", factory.__doc__ or factory.__name__) t = factory(app_state) t.daemon = True # start as daemon thread so that we can terminate app when # we failed to join thread t.start() background_threads.append(t) # make sure the server for our external tilebox is running app_state.tilebox.restart() if open_webbrowser: open_webbrowser_in_background("127.0.0.1", app_state.config.get("web", "port")) try: # wait till someone calls app_state.shutdown_app() while not app_state.wait_for_app_shutdown(timeout=60): # waiting for event without timeout will intercept # KeyboardInterrupts pass except (KeyboardInterrupt, SystemExit): app_state.shutdown_app() log.info("Shutting down") for t in background_threads: t.shutdown() from geobox.utils import join_threads join_threads(background_threads, max_wait_time=10) app_state.cleanup() log.info("Terminating")