Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit e124220

Browse files
committed
Replace multiprocessing by thread worker (fixes #60)
1 parent 75cd784 commit e124220

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

aws_lambda.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import print_function
22
import base64
3+
import concurrent.futures
34
import functools
45
import hashlib
56
import json
6-
import multiprocessing
77
import operator
88
import os
99
import requests
@@ -28,6 +28,9 @@
2828
from kinto_signer.serializer import canonical_json
2929

3030

31+
PARALLEL_REQUESTS = 4
32+
33+
3134
def unpem(pem):
3235
# Join lines and strip -----BEGIN/END PUBLIC KEY----- header/footer
3336
return b"".join([l.strip() for l in pem.split(b"\n")
@@ -73,10 +76,12 @@ def validate_signature(event, context):
7376

7477
# Grab server data in parallel.
7578
start_time = time.time()
76-
pool = multiprocessing.Pool(processes=3)
77-
collections_data = pool.map(functools.partial(download_collection_data, server_url), collections)
78-
pool.close()
79-
pool.join()
79+
collections_data = []
80+
with concurrent.futures.ThreadPoolExecutor(max_workers=PARALLEL_REQUESTS) as executor:
81+
futures = [executor.submit(download_collection_data, server_url, c)
82+
for c in collections]
83+
for future in concurrent.futures.as_completed(futures):
84+
collections_data.append(future.result())
8085
elapsed_time = time.time() - start_time
8186
print(f"Downloaded all data in {elapsed_time:.2f}s")
8287

0 commit comments

Comments
 (0)