I have a short code that uses the multiprocessing
package and works fine on my local machine.
When I uploaded to AWS Lambda
and run there,
I have bumped into the same issue. This is the code I had previously that worked just fine in my local machine:
import concurrent.futures
class Concurrent:
@staticmethod
def execute_concurrently(function, kwargs_list):
results = []
with concurrent.futures.ProcessPoolExecutor() as executor:
for _, result in zip(kwargs_list, executor.map(function, kwargs_list)):
results.append(result)
return results
And I replaced it with this one:
import concurrent.futures
class Concurrent:
@staticmethod
def execute_concurrently(function, kwargs_list):
results = []
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
futures = [executor.submit(function, kwargs) for kwargs in kwargs_list]
for future in concurrent.futures.as_completed(futures):
results.append(future.result())
return results
Works like a charm.
Taken from this pull request