This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to limit or set size for the default ThreadPoolExecutor which be used to run blocking background task in FastAPI? #2961
Comments
@Nohysiwe from concurrent.futures import ThreadPoolExecutor
import asyncio
loop = asyncio.get_running_loop()
loop.set_default_executor(ThreadPoolExecutor(max_workers=4)) |
@insomnes |
@insomnes |
And I find that I can use |
@insomnes # in uvicorn/loops/asyncio.py/asyncio_setup()
def asyncio_setup():
if (
sys.version_info.major >= 3
and sys.version_info.minor >= 8
and platform.system() == "Windows"
):
selector = selectors.SelectSelector()
loop = asyncio.SelectorEventLoop(selector)
asyncio.set_event_loop(loop)
else:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) |
I'm not sure why are you doing this, but... You can add the @insomnes logic inside of this: https://fastapi.tiangolo.com/advanced/events/?h=startup#startup-event |
@Kludex |
The answer for this question is a bit different at the moment, see encode/starlette#1724 (comment) for the answer. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I noticed that blocking background task was running in the default ThreadPoolExecutor for the current thread's asyncio.Eventloop, so how to limit or set size of the default ThreadPoolExecutor. :)
The text was updated successfully, but these errors were encountered: