Skip to content

Instantly share code, notes, and snippets.

@1tgr
Created April 7, 2017 14:24
Show Gist options
  • Save 1tgr/fad0c6bc7cf6445a5c03ea89efb40e71 to your computer and use it in GitHub Desktop.
Save 1tgr/fad0c6bc7cf6445a5c03ea89efb40e71 to your computer and use it in GitHub Desktop.
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