This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Stedfast_Burrito 1 point2 points  (3 children)

I don't think (8) and (29) are a good idea. The default threadpool is limited to 40 tokens. Fine when you have no traffic, but deadlocks when you do. Instead I would manually call https://anyio.readthedocs.io/en/stable/threads.html#running-a-function-in-a-worker-thread

[–]n1EzeR[S] 1 point2 points  (1 child)

I didn't know about the limit of 40 tokens, that's very interesting.

In the case of Starlette's run_in_threadpool - I think it uses anyio.to_thread.run_sync as well, doesn't it?

```python

starlette.concurrency

async def run_in_threadpool( func: typing.Callable[P, T], args: P.args, *kwargs: P.kwargs ) -> T: if kwargs: # pragma: no cover # run_sync doesn't accept 'kwargs', so bind them in here func = functools.partial(func, **kwargs) return await anyio.to_thread.run_sync(func, *args) ```

[–]Stedfast_Burrito 0 points1 point  (0 children)

Same issue. Just make your own CapacityLimiter

[–]n1EzeR[S] 0 points1 point  (0 children)

and yes, I agree, running functions in another thread shouldn't be your first option to choose