forked from micropython/micropython-lib
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pool_async.py
51 lines (38 loc) · 817 Bytes
/
test_pool_async.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
importtime
frommultiprocessingimportPool
deff(x):
returnx*x
pool=Pool(4)
future=pool.apply_async(f, (10,))
assertfuture.get() ==100
deff2(x):
time.sleep(0.5)
returnx+1
future=pool.apply_async(f2, (10,))
iter=0
whilenotfuture.ready():
# print("not ready")
time.sleep(0.1)
iter+=1
assertfuture.get() ==11
assertiter>=5anditer<=8
t=time.time()
futs= [
pool.apply_async(f2, (10,)),
pool.apply_async(f2, (11,)),
pool.apply_async(f2, (12,)),
]
iter=0
whileTrue:
# not all(futs):
c=0
forfinfuts:
ifnotf.ready():
c+=1
ifnotc:
break
# print("not ready2")
time.sleep(0.1)
iter+=1
assertiter>=5anditer<=8
print("Run 3 parallel sleep(1)'s in: ", time.time() -t)