Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Method calls rate limiter #182
Comments
|
@andreportela Hi. No, currently there's nothing like a message queue as in ptb. Example ...
try:
app.send_message(...)
except FloodWait as e:
time.sleep(e.x) # e.x contains the flood wait timeout |
|
Got it. Thanks for the quick answer!! I think this type of feature has such a great potential. It may remove boilerplate, keep things cleaner and simpler. What do you think about including this kind of feature? |
|
@andreportela It can probably help, somehow, but it must also be noted that implementing anything that helps avoiding flood wait errors is almost pointless in an MTProto library such as Pyrogram:
|
|
Now that I think about, what I said previously makes sense in case one wants to completely avoid flood waits. A simpler rate limiter that works globally could be one that caches method calls with all of their arguments and starts denying the next same calls in case a first flood wait was received, until the timeout expires. |
|
That would be one choice. Another one would be to queue those messages and dispatching them in a given rate. I think one doesn't need to exclude the other. Simple constructs like this can be flexibly used by many people. |
|
@andreportela Again, the rate at which the queued messages will be sent can't be assumed because it's still probable to get a flood wait, or worse, introduce delays. |
@delivrance, thanks for your great software and explanations. IMHO this example needs to be improved to help people: as the code catched by the exception has failed due to the flood limitation, it needs to be repeated. Fixed example proposition ...
try:
app.send_message(...)
except FloodWait as e:
time.sleep(e.x) # e.x contains the flood wait timeout
app.send_message(...) # repeat catched codeThe documentation could be improved here: |
I couldn't find a feature to throttle the bot message rate so you can avoid the 429's from the API SPAM limits.
PTB has this feature. I'm not sure if it's the best approach but it seems very useful for larger bots.
Is there a native way that I can do that using Pyrogram?