How to make the request generate different threads


I want to use’ threading.local()’

This is not how Sanic works. It uses asyncio for its concurrent model.

What is your reason for wanting to use threads? If you want to mix and match threads and async tasks, you will need to manage on your own. I generally advise anyone to not mix them.

What about using concurrent.futures.ThreadPoolExecutor in Sanic?

If we create a thread pool, get running loop (sure in case of Sanic it should be uvloop) and then run function in loop.run_in_executor? Would it be the correct way to use threads in asynchronous frameworks like Sanic?

It is possible to do, but I generally do not recommend it unless you know how to do it (in which case you can safeguard it).