asyncio-throttler
asyncio-throttler copied to clipboard
workaround for having todo_list of length 1
Hi, Thanks for the cool library!
I'm wondering what would be the best way to work around the ValueError
from the link below if the todo_list
say, has a single task. I know that's not really the point behind it (as error says), but just say you want to reuse the code you've written (that uses throuttler.run() inside the loop) to work for several tasks and now want to call it with a single task. What would you do, since you can't just provide per_time_window=len(todo_list)-1
since that'd be 0 -- that was the workaround I had when I supplied less than 100 tasks which is the default time window.
https://github.com/scopely/asyncio-throttler/blob/16ffa6facce00a6c4b785725d4b9417b1b1b7e20/asyncio_throttler/throttle.py#L66-L71
To offer more details, the task provided to the throttler also raises ThrottleException
to get re-enqueued, so I wouldn't want to just add that Future
in the event loop without it being wrapped in a Throttler(...).run()
call since it wouldn't know what to do with the ThrottleException
.
Thanks!
I suppose it could just proceed without doing any actual throttling-- the safety check doesn't actually add any safety. A PR here would be welcome-- we're not using this library at present within Scopely so we're unlikely to make the change in-house.