This repository was archived by the owner on Feb 26, 2025. It is now read-only.
File tree 1 file changed +10
-5
lines changed
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 1
1
from __future__ import print_function
2
2
import base64
3
+ import concurrent .futures
3
4
import functools
4
5
import hashlib
5
6
import json
6
- import multiprocessing
7
7
import operator
8
8
import os
9
9
import requests
28
28
from kinto_signer .serializer import canonical_json
29
29
30
30
31
+ PARALLEL_REQUESTS = 4
32
+
33
+
31
34
def unpem (pem ):
32
35
# Join lines and strip -----BEGIN/END PUBLIC KEY----- header/footer
33
36
return b"" .join ([l .strip () for l in pem .split (b"\n " )
@@ -73,10 +76,12 @@ def validate_signature(event, context):
73
76
74
77
# Grab server data in parallel.
75
78
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 ())
80
85
elapsed_time = time .time () - start_time
81
86
print (f"Downloaded all data in { elapsed_time :.2f} s" )
82
87
You can’t perform that action at this time.
0 commit comments