Created
October 16, 2020 22:55
-
-
Save devsetgo/82a1b151c0124cc42ca41eedb0c211f9 to your computer and use it in GitHub Desktop.
Using TQDM and Unsync together.
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
# -*- coding: utf-8 -*- | |
""" | |
This is how to use TQDM and Unsync together. This is for multiple threads. | |
TQDM will keep the main visable after it completes. | |
TQDM will remove the sub thread progress bars as they complete. | |
""" | |
import random | |
import time | |
from tqdm import tqdm | |
from unsync import unsync | |
@unsync | |
def go(): | |
delay: float = random.uniform(0.01, 0.2) | |
loops: int = random.randint(1, 30) | |
for _ in tqdm(range(loops), desc="stuff", ascii=True, leave=False): | |
time.sleep(delay) | |
return "hi" | |
def start(): | |
loops: int = random.randint(100, 1000) | |
tasks = [go() for _ in tqdm(range(loops), ascii=False, leave=True)] | |
results = [task.result() for task in tasks] | |
if __name__ == "__main__": | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment