You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
trio.socket.getaddrinfo (and some of its friends, like socket.resolve_*_address) internally spawn a thread. Right now there's no limited on this, so if you spawn 1000 tasks and they each make a socket connection, you'll briefly get 1000 threads at once. Probably it would be better if you instead, got, like, 20 threads at once, 50 times. Or maybe not, I haven't tried it!
The obvious thing would be to make a global (well, thread-local) semaphore and require getaddrinfo to hold it when calling run_in_worker_thread. Not so obvious how to allow the number of threads to be tuned etc. though.
Probably the easy way to allow thread count tuning is to provide current_getaddrinfo_parallelism, adjust_getaddrinfo_parallelism type functions in trio.socket, that issue the appropriate release/acquire calls. (This might need to allow for semaphores to become negative? The other option is that adjusting down could block, but that seems a bit annoying and pointless? or maybe it's fine idk)
- New synchronization primitive: CapacityLimiter. Like a Semaphore but
more specialized. See python-triogh-182 for rationale.
- Add limiter= argument to run_in_worker_thread, that allows one to
correctly (modulo
python-trio#6 (comment))
control the number of active threads.
- Added new function current_default_worker_thread_limiter(), which
creates or returns a run-local CapacityLimiter, and made
run_in_worker_thread use it by default when no other limiter= is
given.
Closes: python-triogh-10, python-triogh-57, python-triogh-156
trio.socket.getaddrinfo
(and some of its friends, likesocket.resolve_*_address
) internally spawn a thread. Right now there's no limited on this, so if you spawn 1000 tasks and they each make a socket connection, you'll briefly get 1000 threads at once. Probably it would be better if you instead, got, like, 20 threads at once, 50 times. Or maybe not, I haven't tried it!The obvious thing would be to make a global (well, thread-local) semaphore and require
getaddrinfo
to hold it when callingrun_in_worker_thread
. Not so obvious how to allow the number of threads to be tuned etc. though.See also: #6
The text was updated successfully, but these errors were encountered: