-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (34 loc) · 933 Bytes
/
main.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
from hashlib import sha1
import threading
import time
from lambda_pond import Pool
def f(x):
result = ''
s = ''
for m in range(10**3):
s += str(m) + str(x)
result = sha1(s.encode()).hexdigest()
return result
def lambda_handler(event, context):
start = time.time()
with Pool(task_timeout=1) as p:
tasks = []
for n in range(10):
t = p.apply_async(f, n)
tasks.append(t)
print(">>>", len(tasks))
for t in tasks:
print(t.result)
print(">>> multiprocessing: ", time.time() - start)
print('Active threads:', threading.enumerate())
start = time.time()
print(">>>", len(tasks))
for t in tasks:
print(t.result)
for n in range(10):
print(n)
f(n)
print("--- sequential", time.time() - start)
if __name__ == "__main__":
lambda_handler(None, None)
print(threading.enumerate())