Пример #1
0
def _serve() -> None:
    """
    Start the  pywhoami server
    """
    hypercorn_config = hypercorn.Config()
    hypercorn_config.bind = _get_bind()
    asyncio.run(hypercorn.asyncio.serve(app, hypercorn_config))
Пример #2
0
    def hypercorn_cli(
        worker_class: str,
        configuration: str,
        application: str,
        bind: str,
        log_level: str,
    ):
        sys.path.insert(0, os.getcwd())
        asgi_app = import_from_string(application)
        config = hypercorn.Config()
        if configuration is not None:
            if configuration.endswith(".py"):
                config.from_pyfile(configuration)
            elif configuration.endswith(".toml"):
                config.from_toml(configuration)
            else:
                click.secho(
                    "Please use configuration file path endswith `.py` or `.toml`.",
                    fg="red",
                )
                raise SystemExit(1)
        config.bind = [bind]
        config.loglevel = log_level.upper()
        config.worker_class = worker_class

        create_signal_handle = lambda shutdown_event: lambda sig, frame: (
            setattr(asgi_app, "should_exit", True),  # type: ignore
            shutdown_event.set(),
        )
        if worker_class == "uvloop":
            import uvloop

            uvloop.install()
        if worker_class in ("asyncio", "uvloop"):
            import asyncio

            from hypercorn.asyncio import serve

            loop = asyncio.get_event_loop()

            shutdown_event = asyncio.Event(loop=loop)
            for sig in {signal.SIGINT, signal.SIGTERM}:
                signal.signal(sig, create_signal_handle(shutdown_event))

            loop.run_until_complete(
                serve(asgi_app, config, shutdown_trigger=shutdown_event.wait)  # type: ignore
            )
        else:
            import trio
            from hypercorn.trio import serve  # type: ignore

            shutdown_event = trio.Event()
            for sig in {signal.SIGINT, signal.SIGTERM}:
                signal.signal(sig, create_signal_handle(shutdown_event))

            trio.run(serve(asgi_app, config, shutdown_trigger=shutdown_event.wait))  # type: ignore
Пример #3
0
async def app_serve(app, host, port):
    import hypercorn
    import hypercorn.trio.run
    import quart.logging
    config = hypercorn.Config()
    config.host = host
    config.port = port
    config.access_log_format = '%(h)s %(r)s %(s)s %(b)s %(D)s'
    config.access_logger = quart.logging.create_serving_logger()
    config.error_logger = config.access_logger
    config.application_path = None
    hypercorn.trio.run.load_application = lambda *_: app
    await hypercorn.trio.run.run_single(config)
Пример #4
0
async def start():
    log.debug("Running webserver..")
    config = hypercorn.Config()
    port = get_int_key('API_PORT')
    config.bind = [f"localhost:{port}"]
    await hypercorn.asyncio.serve(quart, config)
Пример #5
0
 async def start_quart():
     config = hypercorn.Config()
     config.bind = ["0.0.0.0:6969"]
     # noinspection PyUnresolvedReferences
     await hypercorn.asyncio.serve(self.quart_app, config)
Пример #6
0
async def start():
    log.debug("Running webserver..")
    config = hypercorn.Config()
    config.bind = ["localhost:8085"]
    await hypercorn.asyncio.serve(quart, config)
Пример #7
0
except ImportError:
    pass

shutdown_event = asyncio.Event()


@app.after_serving
async def shutdown():
    pass


def signal_handler():
    shutdown_event.set()


hypercorn_cfg = hypercorn.Config()
try:
    hypercorn_cfg.bind = [
        f"{config.HOST}:{config.PORT}", f"[{config.HOST_IPV6}]:{config.PORT}"
    ]
except NameError:
    hypercorn_cfg.bind = [
        f"{os.environ['HOST']}:{os.environ['PORT']}",
        f"[{os.environ['HOST_IPV6']}]:{os.environ['PORT']}"
    ]

loop = asyncio.get_event_loop()
loop.add_signal_handler(signal.SIGINT, signal_handler)
loop.run_until_complete(
    hypercorn.asyncio.serve(app,
                            hypercorn_cfg,
Пример #8
0
 async def start_quart():
     config = hypercorn.Config()
     config.bind = ["0.0.0.0:6969"]
     await hypercorn.asyncio.serve(self.app, config)