1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import asyncio import time from concurrent.futures import ProcessPoolExecutor from datetime import datetime
import uvicorn from fastapi import FastAPI from fastapi.concurrency import run_in_threadpool
app = FastAPI()
def c(): t = time.perf_counter() for i in range(10**8 * 5): pass print(time.perf_counter() - t) return 1
@app.get("/f") async def f(): print(datetime.now()) r = await run_in_threadpool(c) return r
if __name__ == "__main__": uvicorn.run(app, host="127.0.0.1", port=8000)
|