-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Async coroutine support #91
Conversation
37a3a75
to
fdb485a
Compare
Current coverage is
|
How ever, there is much more to consider to unit test it:
If that works well, you can also make an async context manager : https://docs.python.org/3/reference/datamodel.html#asynchronous-context-managers |
Wow thank you very much sametmax, this sure helps a lot ! I'll train a bit
|
8cade97
to
a65e347
Compare
6ec00f1
to
4b6476a
Compare
Just ran into this issue myself. Bumping this PR.
|
tqdm/_tqdm.py
Outdated
@@ -409,6 +409,20 @@ def __exit__(self, *exc): | |||
self.close() | |||
return False | |||
|
|||
@_coroutine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this one should not be a coroutine.
This works for me: from tqdm.auto import tqdm
def __aiter__(self):
return self
async def __anext__(self):
try:
self.update()
return await self.iterable.__anext__()
except StopIteration:
self.close()
raise StopAsyncIteration
tqdm.__aiter__ = __aiter__
tqdm.__anext__ = __anext__
################################################
async for row in tqdm(con.cursor('SELECT * FROM pageviews ORDER BY user_id')):
pass |
ah nice, I suppose I should take over. @AlJohri could you write a unit test? |
@casperdcl will this be merged soon? |
Signed-off-by: Stephen L. <lrq3000@gmail.com>
fdb485a
to
f858b71
Compare
Codecov Report
@@ Coverage Diff @@
## master #91 +/- ##
==========================================
- Coverage 87.16% 86.46% -0.71%
==========================================
Files 21 21
Lines 1278 1293 +15
Branches 217 218 +1
==========================================
+ Hits 1114 1118 +4
- Misses 143 154 +11
Partials 21 21 |
Add asynchronized coroutine support in
tqdm
as proposed in #65.Code thank's to @aplavin, from here and here.
This code wasn't tested out, can someone devise an example case? (I'm inexperienced with Python coroutines :S).