Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making this work with stable Covalent #93

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
patched mpire to avoid multiprocessing issues on lambda
  • Loading branch information
kessler-frost committed Nov 7, 2023
commit a4d6e02034f4e525725515fbe779d29e4bd95e68
14 changes: 9 additions & 5 deletions covalent_awslambda_plugin/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import boto3
import cloudpickle as pickle

from unittest.mock import patch, MagicMock


def handler(event, context):
try:
Expand All @@ -41,12 +43,14 @@ def handler(event, context):
s3 = boto3.client("s3")
s3.download_file(s3_bucket, func_filename, local_func_filename)

with open(local_func_filename, "rb") as f:
function, args, kwargs = pickle.load(f)
# Patching mpire to avoid issues with multiprocessing on AWS Lambda
with patch.dict('sys.modules', {'mpire': MagicMock()}):
with open(local_func_filename, "rb") as f:
function, args, kwargs = pickle.load(f)

result = function(*args, **kwargs)
with open(local_result_filename, "wb") as f:
pickle.dump(result, f)
result = function(*args, **kwargs)
with open(local_result_filename, "wb") as f:
pickle.dump(result, f)

s3.upload_file(local_result_filename, s3_bucket, result_filename)
except Exception as ex:
Expand Down