-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Give run_in_worker_thread a semaphore= argument #57
Comments
Might make more sense to have it accept an arbitrary async context manager that we enter on the way in and exit on the way out. (Example use case: want to acquire two semaphores, to enforce both a global and local limit like in #6 (comment).) Or could even accept a tuple of async context managers, just like how |
Instead of supporing arbitrary async context managers, I think we should support arbitrary objects that have And let's say it takes values (It also occurred to me that it might make sense to use a |
- 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
- 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
This got fixed in #181, not sure why GH didn't close it. |
If you want to limit the number of simultaneous threads, a semaphore is good for that. But right now it doesn't quite work with
run_in_worker_thread(..., cancellable=True)
because you lose track of the thread once it's cancelled. The idea here would be that if cancelled thenrun_in_worker_thread
returns immediately... but the semaphore doesn't get released until the thread actual exits.The text was updated successfully, but these errors were encountered: