trio icon indicating copy to clipboard operation
trio copied to clipboard

Allow `CapacityLimiter` to have `total_tokens=0`

Open Zac-HD opened this issue 9 months ago • 1 comments

Sometimes, there are use-cases where you want to entirely pause processing of some tasks, and then later scale back up. CapacityLimiter is basically perfect for this kind of thing, except that it currently raises an error if you pass total_tokens=0:

https://github.com/python-trio/trio/blob/d988edd368f094855bd1c36442302113f45f2a1c/src/trio/_sync.py#L254-L255

It's already possible to get the desired effect just by deliberately "leaking" one of the tokens, but it would be much nicer to simply allow zero as the intended capacity, by editing the numbers in the setter above.

Zac-HD avatar Apr 04 '25 13:04 Zac-HD

Might need to make sure this is tested too, since zero is rather susceptible to edge cases. Looks safe though.

TeamSpen210 avatar Apr 05 '25 08:04 TeamSpen210

@Zac-HD , I'm interested, could you kindly assign me this task

kachida avatar Jul 03 '25 03:07 kachida

Hi @kachida any progress? If not, would you mind un-assigning yourself?

You should be able to re-assign yourself whenever you have the time and want to fix this issue.

A5rocks avatar Aug 05 '25 00:08 A5rocks