blob: d4409ede5d9ae6640886f39d84467ddffd955544 (
plain)
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
|
import time
from pyecsca.misc.utils import TaskExecutor
def run(a, b):
return a + b
def wait(a, b):
time.sleep(1)
return a + b
def test_executor():
with TaskExecutor(max_workers=2) as pool:
for i in range(10):
pool.submit_task(i,
run,
i, 5)
for i, future in pool.as_completed():
res = future.result()
assert res == i + 5
def test_executor_no_wait():
with TaskExecutor(max_workers=2) as pool:
for i in range(2):
pool.submit_task(i,
wait,
i, 5)
futures = list(pool.as_completed(wait=False))
assert len(futures) == 0
time.sleep(2.5)
futures = list(pool.as_completed(wait=False))
assert len(futures) == 2
|