Use `asyncio.create_task` instead of `asyncio.ensure_future`
@@ -9,13 +9,13 @@ from uvicorn import Config, Server
@asynccontextmanager
async def run_server(config: Config, sockets=None):
server = Server(config=config)
- cancel_handle = asyncio.ensure_future(server.serve(sockets=sockets))
+ task = asyncio.create_task(server.serve(sockets=sockets))
await asyncio.sleep(0.1)
try:
yield server
finally:
await server.shutdown()
- cancel_handle.cancel()
+ task.cancel()
@contextmanager
