Skip to content

Instantly share code, notes, and snippets.

@tuulos
Created June 30, 2021 05:04
Show Gist options
  • Save tuulos/ca8029e3d2ce8141226e4b7a474f4750 to your computer and use it in GitHub Desktop.
Save tuulos/ca8029e3d2ce8141226e4b7a474f4750 to your computer and use it in GitHub Desktop.
from metaflow import FlowSpec, step
class HelloWorldFlow(FlowSpec):
@step
def start(self):
print("This is start step")
import time
print("<<BEGIN>> 10")
for i in range(10):
print('<<ITER>>')
time.sleep(1)
if i == 5:
print('Show a message while progressbar active')
print('done!')
self.next(self.end)
@step
def end(self):
print("This is end step")
if __name__ == '__main__':
HelloWorldFlow()
import sys
import re
from tqdm import tqdm
RE = re.compile('(\<\<.+?\>\>)( .+)?')
bar = None
barmax = None
for line in sys.stdin:
m = RE.search(line)
if m:
if m.group(1) == '<<BEGIN>>':
barmax = int(m.group(2))
bar = tqdm(leave=False, total=barmax)
elif bar and m.group(1) == '<<ITER>>':
bar.update()
barmax -= 1
if barmax == 0:
bar.close()
bar = None
elif bar:
bar.write(line.strip())
else:
sys.stdout.write(line)
@sangwoo-joh
Copy link

This is a kind of subtle way to detour for showing progress bar of foreach in metaflow, but it works fine.
Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment