Created
June 30, 2021 05:04
-
-
Save tuulos/ca8029e3d2ce8141226e4b7a474f4750 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!