-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtqdm_test.py
57 lines (38 loc) · 1.29 KB
/
tqdm_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: popunbom <[email protected]>
# Created At: 2019/12/06
from time import sleep
from tqdm import trange, tqdm
from multiprocessing import Pool, current_process
import re
from utils.pool import CustomPool
def progresser_1(n):
interval = 0.001 / (n + 2)
worker_id = current_process()._identity[0]
text = f"Worker #{worker_id} "
total = 5000
for _ in trange(total, desc=text, position=worker_id, leave=False):
sleep(interval)
def progresser_2(n):
worker_id = current_process()._identity[0]
text = f"Worker #{worker_id} "
total = 500000
s = 0
for _ in trange(total, desc=text, position=worker_id, leave=False):
s += s * (s % 3)
def proc_1():
cp = CustomPool()
with cp.Pool(n_process=4, initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),)) as p:
for result in tqdm(p.imap_unordered(progresser_1, range(10)), total=10):
pass
cp.update()
def proc_2():
cp = CustomPool()
with cp.Pool(n_process=4, initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),)) as p:
for result in tqdm(p.imap_unordered(progresser_2, range(10)), total=10):
pass
cp.update()
if __name__ == '__main__':
proc_1()
proc_2()