-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
add tqdm.asyncio
#1004
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
add tqdm.asyncio
#1004
Conversation
Codecov Report
@@ Coverage Diff @@
## devel #1004 +/- ##
==========================================
+ Coverage 87.16% 87.42% +0.25%
==========================================
Files 21 22 +1
Lines 1278 1320 +42
Branches 217 223 +6
==========================================
+ Hits 1114 1154 +40
Misses 143 143
- Partials 21 23 +2 |
I have one question about your design. If I understand your code correctly, |
yes exactly. This PR aims to address multiple issues for ease of use. Also as I understand from tqdm.auto import tqdm as tqdm_auto
# based on http://www.dabeaz.com/coroutines/copipe.py
def autonext(func):
def inner(*args, **kwargs):
res = func(*args,**kwargs)
res.next()
return res
return inner
class tqdm_coro(tqdm_auto):
@classmethod
@autonext
def pipe(cls, target, **tkwargs):
"""
Python2 coroutine-style pipe.
This:
r = receiver()
p = producer(r)
r.next()
p.next()
Becomes:
r = receiver()
t = tqdm.pipe(r)
p = producer(t)
r.next()
p.next()
"""
with cls(**tkwargs) as pbar:
while True:
obj = (yield)
target.send(obj)
pbar.update()
def source(target):
for i in ["foo", "bar", "baz", "pythonista", "python", "py"]:
target.send(i)
@autonext
def grep(pattern, target):
while True:
line = (yield)
if pattern in line:
target.send(line)
@autonext
def sink():
while True:
line = (yield)
tqdm_coro.write(line)
source(
tqdm_coro.pipe(
grep('python',
sink()))) |
I don't have the bandwidth in my own projects so I started only supporting Python 3.6+. Looking at the classifiers on PyPI, you go as far back as supporting 2.6 which is pretty tough I think. As far as I understood the topic so far, all asynchronous functions are coroutines. The syntax simply changed from the |
I'm talking about something which predates even In python2, the word coroutine referred to a type of generator obect driven by |
Signed-off-by: Stephen L. <lrq3000@gmail.com>
Thank you for making this happen @casperdcl 🙂 |
whew all done in |
Would love to call this
tqdm.async
but unfortunatelyasync
is a reserved keyword.asyncio
coroutine
,asynchronous
, ...as_completed
wrapperadd async context managerwhy? don't see any use case (async with tqdm() as t
?)support async updatewhy? don't see any use case (await update()
? lol...)examples/
folderExamples:
CC other participants: @Midnighter @sametmax @malarinv @Ekevoo
CC 👍 reactors: @AdrienPensart @supermodo @lukaville @mikulas-mrva @WestXu @SCoder12 @malarinv
Disclaimer: I wrap C++ and/or CUDA anytime I need real concurrent speed, but don't use async Python much so don't know if I'm missing something. Feedback would be appreciated ❤️