Created
April 7, 2017 14:24
-
-
Save 1tgr/fad0c6bc7cf6445a5c03ea89efb40e71 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 random | |
import time | |
from concurrent import futures | |
from concurrent.futures import ThreadPoolExecutor | |
from tqdm import tqdm | |
def run(task_num): | |
with tqdm(range(100), desc='Task %d' % task_num, position=task_num) as progress: | |
for _ in progress: | |
time.sleep(float(random.randint(10, 100)) / 100) | |
if __name__ == '__main__': | |
with ThreadPoolExecutor(max_workers=4) as executor: | |
tasks = [executor.submit(run, task_num) for task_num in range(10)] | |
for task in futures.as_completed(tasks): | |
task.result() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment