當前位置: 首頁>>代碼示例>>Python>>正文


Python uvloop.install方法代碼示例

本文整理匯總了Python中uvloop.install方法的典型用法代碼示例。如果您正苦於以下問題:Python uvloop.install方法的具體用法?Python uvloop.install怎麽用?Python uvloop.install使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在uvloop的用法示例。


在下文中一共展示了uvloop.install方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def main(ctx: click.Context, config_path: Path, debug: bool) -> None:

    cfg = load_config(config_path, debug)
    multiprocessing.set_start_method('spawn')

    if ctx.invoked_subcommand is None:
        cfg['manager']['pid-file'].write_text(str(os.getpid()))
        log_sockpath = Path(f'/tmp/backend.ai/ipc/manager-logger-{os.getpid()}.sock')
        log_sockpath.parent.mkdir(parents=True, exist_ok=True)
        log_endpoint = f'ipc://{log_sockpath}'
        try:
            logger = Logger(cfg['logging'], is_master=True, log_endpoint=log_endpoint)
            with logger:
                ns = cfg['etcd']['namespace']
                setproctitle(f"backend.ai: manager {ns}")
                log.info('Backend.AI Gateway {0}', __version__)
                log.info('runtime: {0}', env_info())
                log_config = logging.getLogger('ai.backend.gateway.config')
                log_config.debug('debug mode enabled.')

                if cfg['manager']['event-loop'] == 'uvloop':
                    import uvloop
                    uvloop.install()
                    log.info('Using uvloop as the event loop backend')
                try:
                    aiotools.start_server(server_main_logwrapper,
                                          num_workers=cfg['manager']['num-proc'],
                                          args=(cfg, log_endpoint))
                finally:
                    log.info('terminated.')
        finally:
            if cfg['manager']['pid-file'].is_file():
                # check is_file() to prevent deleting /dev/null!
                cfg['manager']['pid-file'].unlink()
    else:
        # Click is going to invoke a subcommand.
        pass 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:39,代碼來源:server.py

示例2: _new_run

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def _new_run(func, *args, backend=None, backend_options=None):
    if backend is None:
        backend = os.getenv("PURERPC_BACKEND", "asyncio")
    log.info("Selected {} backend".format(backend))
    if backend == "uvloop":
        import uvloop
        uvloop.install()
        backend = "asyncio"
    return _anyio_run(func, *args, backend=backend, backend_options=backend_options) 
開發者ID:standy66,項目名稱:purerpc,代碼行數:11,代碼來源:anyio_monkeypatch.py

示例3: execute

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def execute(argv: Sequence[str] = None):
    """Entrypoint."""
    parser = ArgumentParser()
    parser.prog += " start"
    get_settings = init_argument_parser(parser)
    args = parser.parse_args(argv)
    settings = get_settings(args)
    common_config(settings)

    # set ledger to read only if explicitely specified
    settings["ledger.read_only"] = settings.get("read_only_ledger", False)

    # Support WEBHOOK_URL environment variable
    webhook_url = os.environ.get("WEBHOOK_URL")
    if webhook_url:
        webhook_urls = list(settings.get("admin.webhook_urls") or [])
        webhook_urls.append(webhook_url)
        settings["admin.webhook_urls"] = webhook_urls

    # Create the Conductor instance
    context_builder = DefaultContextBuilder(settings)
    conductor = Conductor(context_builder)

    # Run the application
    if uvloop:
        uvloop.install()
        print("uvloop installed")
    run_loop(start_app(conductor), shutdown_app(conductor)) 
開發者ID:hyperledger,項目名稱:aries-cloudagent-python,代碼行數:30,代碼來源:start.py

示例4: setUp

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def setUp(self):
        uvloop.install() 
開發者ID:formony,項目名稱:ton_client,代碼行數:4,代碼來源:test_asyncio.py

示例5: serve_grpclib_uvloop

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def serve_grpclib_uvloop():
    import uvloop
    uvloop.install()

    asyncio.run(_grpclib_server()) 
開發者ID:vmagamedov,項目名稱:grpclib,代碼行數:7,代碼來源:bench.py

示例6: serve_grpcio_uvloop

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def serve_grpcio_uvloop():
    import uvloop
    uvloop.install()

    from _reference.server import serve

    try:
        asyncio.run(serve())
    except KeyboardInterrupt:
        pass 
開發者ID:vmagamedov,項目名稱:grpclib,代碼行數:12,代碼來源:bench.py

示例7: serve_aiohttp_uvloop

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def serve_aiohttp_uvloop():
    import uvloop
    uvloop.install()

    _aiohttp_server() 
開發者ID:vmagamedov,項目名稱:grpclib,代碼行數:7,代碼來源:bench.py

示例8: main

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def main() -> None:
    app = init_app()
    app_settings = app['config']['app']

    {%- if cookiecutter.use_uvloop == 'y' %}
    uvloop.install()
    {%- endif %}
    web.run_app(
        app,
        host=app_settings['host'],
        port=app_settings['port'],
    ) 
開發者ID:aio-libs,項目名稱:create-aio-app,代碼行數:14,代碼來源:__main__.py

示例9: main

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def main():
    try:
        # noinspection PyUnresolvedReferences
        import uvloop

        logger.debug("Setting up with uvloop.")
        uvloop.install()
    except ImportError:
        pass

    bot = ModmailBot()
    bot.run() 
開發者ID:kyb3r,項目名稱:modmail,代碼行數:14,代碼來源:bot.py

示例10: main

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def main():
    if uvloop is not None:
        uvloop.install()
    asyncio.run(async_main()) 
開發者ID:Chia-Network,項目名稱:chia-blockchain,代碼行數:6,代碼來源:start_timelord.py

示例11: run_service

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def run_service(*args, **kwargs):
    if uvloop is not None:
        uvloop.install()
    # TODO: use asyncio.run instead
    # for now, we use `run_until_complete` as `asyncio.run` blocks on RPC server not exiting
    if 1:
        return asyncio.get_event_loop().run_until_complete(
            async_run_service(*args, **kwargs)
        )
    else:
        return asyncio.run(async_run_service(*args, **kwargs)) 
開發者ID:Chia-Network,項目名稱:chia-blockchain,代碼行數:13,代碼來源:start_service.py

示例12: main

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def main():
    if uvloop is not None:
        uvloop.install()
    asyncio.run(start_websocket_server()) 
開發者ID:Chia-Network,項目名稱:chia-blockchain,代碼行數:6,代碼來源:start_wallet.py

示例13: __init__

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def __init__(self, debug=False):
        self.debug = debug
        if not self.debug:
            uvloop.install()

        self.loop = asyncio.get_event_loop()
        self._prepare()
        self.proxyman = ProxyMan(self.listen_host) 
開發者ID:Ehco1996,項目名稱:aioshadowsocks,代碼行數:10,代碼來源:app.py

示例14: init_uvloop

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def init_uvloop():
    import uvloop
    uvloop.install() 
開發者ID:DevAlone,項目名稱:proxy_py,代碼行數:5,代碼來源:main.py

示例15: setup_asyncio

# 需要導入模塊: import uvloop [as 別名]
# 或者: from uvloop import install [as 別名]
def setup_asyncio(config: util.config.Config) -> asyncio.AbstractEventLoop:
    """Returns a new asyncio event loop with settings from the given config."""

    asyncio_config: util.config.AsyncIOConfig = config["asyncio"]

    if sys.platform == "win32":
        # Force ProactorEventLoop on Windows for subprocess support
        policy = asyncio.WindowsProactorEventLoopPolicy()
        asyncio.set_event_loop_policy(policy)
    elif not asyncio_config["disable_uvloop"]:
        # Initialize uvloop if available
        try:
            # noinspection PyUnresolvedReferences
            import uvloop

            uvloop.install()
            log.info("Using uvloop event loop")
        except ImportError:
            pass

    loop = asyncio.new_event_loop()

    if asyncio_config["debug"]:
        log.info("Enabling asyncio debug mode")
        loop.set_debug(True)

    return loop 
開發者ID:kdrag0n,項目名稱:pyrobud,代碼行數:29,代碼來源:launch.py


注:本文中的uvloop.install方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。