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 on_shutdown(self): try: logging.info("Shutting down icon cache updates") iconcache.icon_cache_updater.shutdown() logging.info("Shutting down movie data updates") moviedata.movie_data_updater.shutdown() logging.info("Joining event loop ...") eventloop.join() logging.info("Saving preferences...") app.config.save() logging.info("Done shutting down.") logging.info("Remaining threads are:") for thread in threading.enumerate(): logging.info("%s", thread) except StandardError: signals.system.failed_exn("while shutting down") exit_miro(1)
def on_shutdown(self): try: eventloop.join() logging.info("Saving preferences...") app.config.save() logging.info("Shutting down icon cache updates") iconcache.iconCacheUpdater.shutdown() logging.info("Shutting down movie data updates") moviedata.movie_data_updater.shutdown() logging.info("Done shutting down.") logging.info("Remaining threads are:") for thread in threading.enumerate(): logging.info("%s", thread) except (SystemExit, KeyboardInterrupt): raise except: signals.system.failed_exn("while shutting down") exit_miro(1)