Spaces:
Sleeping
Sleeping
File size: 474 Bytes
fa81432 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import random
from concurrent.futures import ThreadPoolExecutor, as_completed
from time import sleep
from tqdm import tqdm
import traceback
def mp_handler(job):
try:
sleep(random.randint(1,20))
print(job)
except KeyboardInterrupt:
exit(0)
except:
traceback.print_exc()
p = ThreadPoolExecutor(2)
futures = [p.submit(mp_handler, j) for j in range(100)]
_ = [r.result() for r in tqdm(as_completed(futures), total=len(futures))]
|