Пример #1
0
def run_daemon(args: argparse.Namespace, conf: Config):
    loop = asyncio.get_event_loop()
    if args.verbose is not None:
        loop.set_debug(True)
    if not args.no_logging:
        setup_logging(logging.getLogger(), args, conf)
    daemon = Daemon(conf)

    def __exit():
        raise GracefulExit()

    try:
        loop.add_signal_handler(signal.SIGINT, __exit)
        loop.add_signal_handler(signal.SIGTERM, __exit)
    except NotImplementedError:
        pass  # Not implemented on Windows

    try:
        loop.run_until_complete(daemon.start())
        loop.run_forever()
    except (GracefulExit, KeyboardInterrupt, asyncio.CancelledError):
        pass
    finally:
        loop.run_until_complete(daemon.stop())
        logging.shutdown()

    if hasattr(loop, 'shutdown_asyncgens'):
        loop.run_until_complete(loop.shutdown_asyncgens())
Пример #2
0
def run_daemon(args: argparse.Namespace, conf: Config):
    if sys.version_info < (3, 8) and platform.system() == "Windows":
        # TODO: remove after we move to requiring Python 3.8
        asyncio.set_event_loop(asyncio.ProactorEventLoop())
    loop = asyncio.get_event_loop()
    if args.verbose is not None:
        loop.set_debug(True)
    if not args.no_logging:
        setup_logging(logging.getLogger(), args, conf)
    daemon = Daemon(conf)

    def __exit():
        raise GracefulExit()

    try:
        loop.add_signal_handler(signal.SIGINT, __exit)
        loop.add_signal_handler(signal.SIGTERM, __exit)
    except NotImplementedError:
        pass  # Not implemented on Windows

    try:
        loop.run_until_complete(daemon.start())
        loop.run_forever()
    except (GracefulExit, KeyboardInterrupt, asyncio.CancelledError):
        pass
    finally:
        loop.run_until_complete(daemon.stop())
        logging.shutdown()

    if hasattr(loop, 'shutdown_asyncgens'):
        loop.run_until_complete(loop.shutdown_asyncgens())
Пример #3
0
def start():
    keyring.set_keyring(LbryAndroidKeyring())
    private_storage_dir = lbrynet_android_utils.getAppInternalStorageDir(service.getApplicationContext())
    configured_download_dir = lbrynet_android_utils.getConfiguredDownloadDirectory(service.getApplicationContext())
    components_to_skip = []

    dht_state = 'off'
    try:
        dht_path = f'{private_storage_dir}/dht';
        with open(dht_path, 'r') as file:
            dht_state = file.read()
    except:
        pass

    dht_enabled = dht_state == 'on'
    if not dht_enabled:
        components_to_skip = [DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT]

    conf = Config(
        data_dir=f'{private_storage_dir}/lbrynet',
        wallet_dir=f'{private_storage_dir}/lbryum',
        download_dir=configured_download_dir,
        blob_lru_cache_size=32,
        components_to_skip=components_to_skip,
        save_blobs=False,
        save_files=False,
        share_usage_data=True,
        use_upnp=False
    )

    for directory in (conf.data_dir, conf.download_dir, conf.wallet_dir):
        ensure_directory_exists(directory)

    configure_logging(conf)
    log.info('Starting lbry sdk {}'.format(lbrynet_version));

    loop = asyncio.get_event_loop()
    loop.set_debug(lbrynet_android_utils.isDebug())

    daemon = Daemon(conf)
    try:
        loop.run_until_complete(daemon.start())
        loop.run_forever()
    except (GracefulExit, asyncio.CancelledError):
        pass
    finally:
        loop.run_until_complete(daemon.stop())
    if hasattr(loop, 'shutdown_asyncgens'):
        loop.run_until_complete(loop.shutdown_asyncgens())