Skip to content

Commit cb0c3d5

Browse files
authored
Compatibility Issue Detected with Python 3.11 and aws lambda (#73)
* Fixed compatibility issue with python3.11 and aws lambda * updated pytest and pytest-cov versions in requirements.txt file * Addressed review comments
1 parent afe1d48 commit cb0c3d5

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

filestack/uploads/intelligent_ingestion.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import os
33
import sys
44
import mimetypes
5+
import multiprocessing
56
import hashlib
67
import logging
78
import functools
89
import threading
910
from urllib3.util.retry import Retry
10-
from multiprocessing.pool import ThreadPool
11+
from concurrent.futures import ThreadPoolExecutor
1112

1213
from base64 import b64encode
1314

@@ -27,7 +28,7 @@
2728
CHUNK_SIZE = 8 * MB
2829
MIN_CHUNK_SIZE = 32 * 1024
2930
MAX_DELAY = 4
30-
NUM_THREADS = 4
31+
NUM_THREADS = multiprocessing.cpu_count()
3132

3233
lock = threading.Lock()
3334

@@ -130,8 +131,8 @@ def upload(apikey, filepath, file_obj, storage, params=None, security=None):
130131
upload_part, apikey, filename, filepath, filesize, storage, start_response
131132
)
132133

133-
with ThreadPool(NUM_THREADS) as pool:
134-
pool.map(fii_upload, parts)
134+
with ThreadPoolExecutor(max_workers=NUM_THREADS) as executor:
135+
list(executor.map(fii_upload, parts))
135136

136137
payload.update({
137138
'uri': start_response['uri'],
@@ -147,7 +148,7 @@ def upload(apikey, filepath, file_obj, storage, params=None, security=None):
147148

148149
complete_url = 'https://{}/multipart/complete'.format(start_response['location_url'])
149150
session = requests.Session()
150-
retries = Retry(total=7, backoff_factor=0.2, status_forcelist=[202], method_whitelist=frozenset(['POST']))
151+
retries = Retry(total=7, backoff_factor=0.2, status_forcelist=[202], allowed_methods=frozenset(['POST']))
151152
session.mount('http://', requests.adapters.HTTPAdapter(max_retries=retries))
152153
response = session.post(complete_url, json=payload, headers=config.HEADERS)
153154
if response.status_code != 200:

filestack/uploads/multipart.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import multiprocessing
55
from base64 import b64encode
66
from functools import partial
7-
from multiprocessing.pool import ThreadPool
7+
from concurrent.futures import ThreadPoolExecutor
88

99
from filestack import config
1010
from filestack.utils import requests
@@ -113,10 +113,10 @@ def multipart_upload(apikey, filepath, file_obj, storage, params=None, security=
113113
chunks = make_chunks(filepath, file_obj, filesize)
114114
start_response = multipart_request(config.MULTIPART_START_URL, payload, params, security)
115115
upload_func = partial(upload_chunk, apikey, filename, storage, start_response)
116-
117-
with ThreadPool(upload_processes) as pool:
118-
uploaded_parts = pool.map(upload_func, chunks)
119-
116+
117+
with ThreadPoolExecutor(max_workers=upload_processes) as executor:
118+
uploaded_parts = list(executor.map(upload_func, chunks))
119+
120120
location_url = start_response.pop('location_url')
121121
payload.update(start_response)
122122
payload['parts'] = uploaded_parts

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
pytest==4.6.3
2-
pytest-cov==2.5.0
1+
pytest>=4.6.3
2+
pytest-cov>=2.5.0
33
requests>=2.31.0
44
responses==0.14.0
55
trafaret==2.0.2

0 commit comments

Comments
 (0)