from sanic import Sanic
from sanic.response import text
import asyncio
import time
import threading
app = Sanic("MyHelloWorldApp")
print(threading.get_ident(), threading.get_native_id())
@app.get("/sync")
async def hello_world(request):
print('start sync', threading.get_ident(), threading.get_native_id())
time.sleep(10) # third-party libraries
return text("Hello, world.")
@app.get("/async")
async def hello_world2(request):
await asyncio.sleep(10)
return text("Hello, world.")
I know that there are methods like asyncio.to_thread(blocking_io), but is this the best practice? I see that if it is not async func in fastapi, it will automatically execute in the thread pool.