-
-
Notifications
You must be signed in to change notification settings - Fork 356
Add trio.CapacityLimiter.wait_no_borrows #2880
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
Add trio.CapacityLimiter.wait_no_borrows #2880
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2880 +/- ##
=======================================
Coverage 99.64% 99.64%
=======================================
Files 116 116
Lines 17501 17532 +31
Branches 3148 3152 +4
=======================================
+ Hits 17439 17470 +31
Misses 43 43
Partials 19 19
|
This is the equivalent of trio.testing.wait_all_tasks_blocked but for anything wrapped by a CapacityLimiter. This is useful when writing tests that use to_thread
65657b2
to
d42a5e0
Compare
I'm worried this will be an attractive nuisance. In tests where you know
exactly what tasks are supposed to be where, it makes total sense, but it
also *sounds* like something that would let you get exclusive access to
whatever the limiter is protecting. But that's not true; by the time it
returns, another task could have already claimed a token.
If the immediate goal is to be able to use it in a few tests, maybe we can
handle those with a less-elegant sleep/check loop, or some other way to
tell when the tasks are done?
…On Sat, Nov 18, 2023, 15:42 Vincent Vanlaer ***@***.***> wrote:
This is the equivalent of trio.testing.wait_all_tasks_blocked but for
anything wrapped by a CapacityLimiter. This is useful when writing tests
that use to_thread
------------------------------
You can view, comment on, or merge this pull request online at:
#2880
Commit Summary
- 65657b2
<65657b2>
Add trio.CapacityLimiter.wait_no_borrows
File Changes
(2 files <https://github.com/python-trio/trio/pull/2880/files>)
- *A* newsfragments/2880.feature.rst
<https://github.com/python-trio/trio/pull/2880/files#diff-48b5966279693fc13aedfb6dd5d8e87ae48f53e1e01da7fa7af5a9da24b6a63e>
(1)
- *M* src/trio/_sync.py
<https://github.com/python-trio/trio/pull/2880/files#diff-76551f8b0157b985ab28f3d374ecf3d756cd56d7544a413df6d1d1e9c06ee641>
8000
;
(23)
Patch Links:
- https://github.com/python-trio/trio/pull/2880.patch
- https://github.com/python-trio/trio/pull/2880.diff
—
Reply to this email directly, view it on GitHub
<#2880>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEU42GHEDQY6S6FFONGDLTYFFBU5AVCNFSM6AAAAAA7RJPVPKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGAYDANRSGE3TMMQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Doesn't the In any case, perhaps another possibility that would communicate the intent better, is to add a function to For context, I'm currently using this function as follows: async def wait_all_blocked():
capacity_limiter = trio.to_thread.current_default_thread_limiter()
while True:
await capacity_limiter.wait_no_borrowers()
await trio.testing.wait_all_tasks_blocked()
if (capacity_limiter.borrowed_tokens == 0):
break |
@njsmith Does my explanation or alternative proposal alleviate your concerns? |
Would a |
I have implemented your suggestion in #2937 as it's a complete reimplementation |
Superseded by #2937 |
This is the equivalent of trio.testing.wait_all_tasks_blocked but for anything wrapped by a CapacityLimiter. This is useful when writing tests that use to_thread.