当前位置: 首页>>代码示例>>Python>>正文


Python Application.register_on_finish方法代码示例

本文整理汇总了Python中aiohttp.web.Application.register_on_finish方法的典型用法代码示例。如果您正苦于以下问题:Python Application.register_on_finish方法的具体用法?Python Application.register_on_finish怎么用?Python Application.register_on_finish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiohttp.web.Application的用法示例。


在下文中一共展示了Application.register_on_finish方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init

# 需要导入模块: from aiohttp.web import Application [as 别名]
# 或者: from aiohttp.web.Application import register_on_finish [as 别名]
def init(loop):
    app = Application(middlewares=[auth_factory])
    app['redis'] = yield from asyncio_redis.Pool.create(host='127.0.0.1',
                                                        port=6379, poolsize=10)
    app.register_on_finish(close_redis)

    app.router.add_route('GET', '/', static)
    app.router.add_route('GET', '/static/{file}', static)
    app.router.add_route('GET', '/chaussette', websocket_handler)
    app.router.add_route('PUT', '/event/{user}', event)
    handler = app.make_handler()
    srv = yield from loop.create_server(handler, '0.0.0.0', 8080)
    return srv, handler, app
开发者ID:bearstech,项目名称:flowpanel,代码行数:15,代码来源:app.py

示例2: configure_server

# 需要导入模块: from aiohttp.web import Application [as 别名]
# 或者: from aiohttp.web.Application import register_on_finish [as 别名]
def configure_server(application, *,

    # Server config.
    host = "0.0.0.0",
    port = 8080,

    # Unix server config.
    unix_socket = None,
    unix_socket_perms = 0o600,

    # Prexisting socket config.
    socket = None,

    # Shared server config.
    backlog = 1024,

    # aiohttp config.
    routes = (),
    static = (),
    on_finish = (),

    # Asyncio config.
    loop = None,

    # Handler config.
    script_name = "",
    **kwargs

):
    loop = loop or asyncio.get_event_loop()
    app = Application(
        loop = loop,
    )
    # Add routes.
    for method, path, handler in routes:
        app.router.add_route(method, path, handler)
    # Add static routes.
    if isinstance(static, Mapping):
        static = static.items()
    for path, dirname in static:
        app.router.add_static(path, dirname)
    # Add on finish callbacks.
    for on_finish_callback in on_finish:
        app.register_on_finish(on_finish_callback)
    # Add the wsgi application. This has to be last.
    app.router.add_route("*", "{}{{path_info:.*}}".format(script_name), WSGIHandler(application, **kwargs).handle_request)
    # Set up the server.
    shared_server_kwargs = {
        "backlog": backlog,
    }
    if unix_socket is not None:
        server_future = loop.create_unix_server(app.make_handler(),
            path = unix_socket,
            **shared_server_kwargs
        )
    elif socket is not None:
        server_future = loop.create_server(app.make_handler(),
            sock = socket,
            **shared_server_kwargs
        )
    else:
        server_future = loop.create_server(app.make_handler(),
            host = host,
            port = port,
            **shared_server_kwargs
        )
    server = loop.run_until_complete(server_future)
    app.logger.info("Serving on http://%s:%s", *parse_sockname(server.sockets[0].getsockname()))
    # Set socket permissions.
    if unix_socket is not None:
        os.chmod(unix_socket, unix_socket_perms)
    # All done!
    return server, app
开发者ID:gogobook,项目名称:aiohttp-wsgi,代码行数:75,代码来源:api.py


注:本文中的aiohttp.web.Application.register_on_finish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。