def startup(): """Startup Miro. This method starts up the eventloop and schedules the rest of the startup to run in the event loop. Frontends should call this method, then wait for 1 of 2 messages StartupSuccess is sent once the startup is done and the backend is ready to go. StartupFailure is sent if something bad happened. initialize() must be called before startup(). """ logging.info("Starting up %s", app.config.get(prefs.LONG_APP_NAME)) logging.info("Version: %s", app.config.get(prefs.APP_VERSION)) logging.info("Revision: %s", app.config.get(prefs.APP_REVISION)) logging.info("Builder: %s", app.config.get(prefs.BUILD_MACHINE)) logging.info("Build Time: %s", app.config.get(prefs.BUILD_TIME)) logging.info("Debugmode: %s", app.debugmode) eventloop.connect('thread-started', finish_startup) logging.info("Reading HTTP Password list") httpauth.init() httpauth.restore_from_file() logging.info("Starting libCURL thread") httpclient.init_libcurl() httpclient.start_thread() logging.info("Starting event loop thread") eventloop.startup() if DEBUG_DB_MEM_USAGE: mem_usage_test_event.wait() load_extensions()
def startup(): """Startup Miro. This method starts up the eventloop and schedules the rest of the startup to run in the event loop. Frontends should call this method, then wait for 1 of 2 messages StartupSuccess is sent once the startup is done and the backend is ready to go. StartupFailure is sent if something bad happened. initialize() must be called before startup(). """ logging.info("Starting up %s", app.config.get(prefs.LONG_APP_NAME)) logging.info("Version: %s", app.config.get(prefs.APP_VERSION)) logging.info("Revision: %s", app.config.get(prefs.APP_REVISION)) logging.info("Builder: %s", app.config.get(prefs.BUILD_MACHINE)) logging.info("Build Time: %s", app.config.get(prefs.BUILD_TIME)) logging.info("Debugmode: %s", app.debugmode) eventloop.connect('thread-started', startup_for_frontend) logging.info("Reading HTTP Password list") httpauth.init() httpauth.restore_from_file() logging.info("Starting libCURL thread") httpclient.init_libcurl() httpclient.start_thread() logging.info("Starting event loop thread") eventloop.startup() if DEBUG_DB_MEM_USAGE: mem_usage_test_event.wait() load_extensions()
def launch_downloader_daemon(): # Increase the maximum file descriptor count (to the max) # NOTE: the info logging is REQUIRED for some unknown reason, if it is not # done here, no further logging can be done in the daemon and it gets stuck. try: import resource logging.info('Increasing file descriptor count limit in Downloader') resource.setrlimit(resource.RLIMIT_NOFILE, (10240, -1)) except ValueError: logging.warn('setrlimit failed.') # Make sure we don't leak from the downloader eventloop from miro import eventloop def beginLoop(loop): loop.pool = Foundation.NSAutoreleasePool.alloc().init() eventloop.connect('begin-loop', beginLoop) eventloop.connect('thread-will-start', beginLoop) def endLoop(loop): del loop.pool eventloop.connect('end-loop', endLoop) eventloop.connect('thread-did-start', endLoop) # And launch from miro.dl_daemon import Democracy_Downloader Democracy_Downloader.launch() # Wait for the event loop thread to finish. # Although this is theorically not necessary since the event loop thread is # a non-daemon thread, situations where the downloader daemon exits right # after its launch as this function returns have been seen in the wild. eventloop.join()
def launch_downloader_daemon(): # Increase the maximum file descriptor count (to the max) # NOTE: the info logging is REQUIRED for some unknown reason, if it is not # done here, no further logging can be done in the daemon and it gets stuck. try: import resource logging.debug('Increasing file descriptor count limit in Downloader') resource.setrlimit(resource.RLIMIT_NOFILE, (10240, -1)) except ValueError: logging.warn('setrlimit failed.') # Make sure we don't leak from the downloader eventloop from miro import eventloop def beginLoop(loop): loop.pool = Foundation.NSAutoreleasePool.alloc().init() eventloop.connect('begin-loop', beginLoop) eventloop.connect('thread-will-start', beginLoop) def endLoop(loop): del loop.pool eventloop.connect('end-loop', endLoop) eventloop.connect('thread-did-start', endLoop) # And launch from miro.dl_daemon import MiroDownloader MiroDownloader.launch() # Wait for the event loop thread to finish. # Although this is theorically not necessary since the event loop thread is # a non-daemon thread, situations where the downloader daemon exits right # after its launch as this function returns have been seen in the wild. eventloop.join()
def __init__(self, path=None, object_schemas=None, schema_version=None): if path is None: path = app.config.get(prefs.SQLITE_PATHNAME) if object_schemas is None: object_schemas = schema.object_schemas if schema_version is None: schema_version = schema.VERSION # version of sqlite3 try: logging.info("Sqlite3 version: %s", sqlite3.sqlite_version) except AttributeError: logging.info("sqlite3 has no sqlite_version attribute.") # version of the sqlite python bindings try: logging.info("Pysqlite version: %s", sqlite3.version) except AttributeError: logging.info("sqlite3 has no version attribute.") db_existed = os.path.exists(path) self.raise_load_errors = False # only gets set in unittests self._dc = None self._query_times = {} self.path = path self._quitting_from_operational_error = False self._object_schemas = object_schemas self._schema_version = schema_version self._schema_map = {} self._schema_column_map = {} self._all_schemas = [] self._object_map = {} # maps object id -> DDBObjects in memory self._ids_loaded = set() self._statements_in_transaction = [] eventloop.connect("event-finished", self.on_event_finished) for oschema in object_schemas: self._all_schemas.append(oschema) for klass in oschema.ddb_object_classes(): self._schema_map[klass] = oschema for field_name, schema_item in oschema.fields: klass.track_attribute_changes(field_name) for name, schema_item in oschema.fields: self._schema_column_map[oschema, name] = schema_item self._converter = SQLiteConverter() self.open_connection() if not db_existed: self._init_database()
def connect_to_signals(self): Application.connect_to_signals(self) eventloop.connect('thread-will-start', self.beginLoop) eventloop.connect('thread-did-start', self.endLoop) eventloop.connect('begin-loop', self.beginLoop) eventloop.connect('end-loop', self.endLoop) httpclient.register_on_start( lambda cm: cm.connect('begin-loop', self.beginLoop)) httpclient.register_on_start( lambda cm: cm.connect('end-loop', self.endLoop))