本文整理汇总了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
示例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)
示例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))
示例4: setUp
# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import install [as 别名]
def setUp(self):
uvloop.install()
示例5: serve_grpclib_uvloop
# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import install [as 别名]
def serve_grpclib_uvloop():
import uvloop
uvloop.install()
asyncio.run(_grpclib_server())
示例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
示例7: serve_aiohttp_uvloop
# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import install [as 别名]
def serve_aiohttp_uvloop():
import uvloop
uvloop.install()
_aiohttp_server()
示例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'],
)
示例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()
示例10: main
# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import install [as 别名]
def main():
if uvloop is not None:
uvloop.install()
asyncio.run(async_main())
示例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))
示例12: main
# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import install [as 别名]
def main():
if uvloop is not None:
uvloop.install()
asyncio.run(start_websocket_server())
示例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)
示例14: init_uvloop
# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import install [as 别名]
def init_uvloop():
import uvloop
uvloop.install()
示例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