-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Keep requesting even the account has rate-limited #27
Comments
Hi, @TNumFive. Thanks for the issue. That was a bug. Fixed in 0.4.1. |
After the update, the ctx never gets closed: async def _get_ctx(self) -> Ctx:
if self.ctx:
return self.ctx
# **this if-statment will never be executed**
if self.ctx is not None:
await self._close_ctx()
acc = await self.pool.get_for_queue_or_wait(self.queue)
clt = acc.make_client()
self.ctx = Ctx(acc, clt)
return self.ctx And there would be an exception like this when I break from async-for (this problem exists before update): async for tweet in api.user_tweets(user.id):
if tweet.id < last_tweet_id:
break
Could it be possible that it's due to ctx not closed properly? |
Hi again, @TNumFive. That of how python works:
On simple example: import asyncio
class Ctx:
async def __aenter__(self):
print("entered")
return self
async def __aexit__(self, exc_type, exc_val, exc_tb):
print("exited")
async def gen():
async with Ctx() as ctx:
for x in range(1, 5):
await asyncio.sleep(0.1)
yield x
async def main():
async for i in gen():
print(i)
if i == 3:
break
print("STOP")
if __name__ == "__main__":
asyncio.run(main()) Output:
So If you want to stop iteration with break, need to use async def main():
from contextlib import aclosing
async with aclosing(gen()) as g:
async for i in g:
print(i)
if i == 3:
break
print("STOP") After this generator will be closed on break:
In your case it should be like: from contextlib import aclosing
async with aclosing(api.user_tweets(user.id)) as gen:
async for tweet in gen:
if tweet.id < last_tweet_id:
break |
That's very nice of you !!! I didn't known about the contextlib stuff, And I just found that you fixed the |
QueueClient will switch context whether current account is rate limited or not, while the context switching itself will unlock that account, cause the script to constantly switch between all loaded accounts no matter limited or not.
How about just remain the lock when switch context? To prevent using account that is already limited.
The text was updated successfully, but these errors were encountered: