Skip to content

Allow CapacityLimiter to have total_tokens=0 #3243

Open
@Zac-HD

Description

@Zac-HD

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:

trio/src/trio/_sync.py

Lines 254 to 255 in d988edd

if new_total_tokens < 1:
raise ValueError("total_tokens must be >= 1")

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions