def auto_loop_setup(reload: bool = False) -> None: try: import uvloop # noqa except ImportError: # pragma: no cover from uvicorn.loops.asyncio import asyncio_setup as loop_setup loop_setup(reload=reload) else: # pragma: no cover from uvicorn.loops.uvloop import uvloop_setup uvloop_setup(reload=reload)
def auto_loop_setup(): try: import uvloop # noqa except ImportError: # pragma: no cover from uvicorn.loops.asyncio import asyncio_setup as loop_setup loop_setup() else: from uvicorn.loops.uvloop import uvloop_setup uvloop_setup()
def main(): uvloop.uvloop_setup() database = ScoutEntriesDatabase(uri=os.environ["POSTGRES_URI"]) host = "0.0.0.0" port = 8000 cfg = uvicorn.config.Config(app=WebServer(database).app, host=host, port=port) server = Server(cfg) server.run()
def auto_loop_setup(): try: import uvloop except ImportError as exc: # pragma: no cover if sys.platform == "win32": from uvicorn.loops.iocp import iocp_setup as loop_setup else: from uvicorn.loops.asyncio import asyncio_setup as loop_setup loop_setup() else: from uvicorn.loops.uvloop import uvloop_setup uvloop_setup()
def auto_loop_setup(): try: import uvloop except ImportError as exc: # pragma: no cover from uvicorn.loops.asyncio import asyncio_setup return asyncio_setup() else: from uvicorn.loops.uvloop import uvloop_setup return uvloop_setup()
def run(self): ## In subprocess ## uvloop_setup() loop = asyncio.get_event_loop() loop.run_until_complete(self.serve())
logging.info(f"message {data}") # await device.set(data) @sio.on('disconnect') async def disconnect(sid): logging.info(f'disconnect {sid}') # Set up the event loop async def start_background_tasks(): while True: logging.info(f"Background tasks that ticks every 10s.") await sio.sleep(10.0) async def start_uvicorn(): uvicorn.run(app, host='0.0.0.0', port=8000) async def main(loop): bg_task = loop.create_task(start_background_tasks()) uv_task = loop.create_task(start_uvicorn()) await asyncio.wait([bg_task, uv_task]) if __name__ == '__main__': uvloop_setup() loop = asyncio.get_event_loop() loop.run_until_complete(main(loop)) loop.close()