Skip to content

Commit

Permalink
trying patching mpire with sys.modules
Browse files Browse the repository at this point in the history
  • Loading branch information
kessler-frost committed Nov 7, 2023
1 parent 7855400 commit 88fef2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion covalent_awslambda_plugin/assets/infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

variable "name" {
default = "covalent-lambda"
default = "sankalp-covalent-lambda"
description = "Prefix to use for all provisioned resources"
}

Expand Down
16 changes: 9 additions & 7 deletions covalent_awslambda_plugin/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import boto3
import cloudpickle as pickle

from unittest.mock import patch, MagicMock
from unittest.mock import MagicMock
import sys


def handler(event, context):
Expand All @@ -44,13 +45,14 @@ def handler(event, context):
s3.download_file(s3_bucket, func_filename, local_func_filename)

# Patching mpire to avoid issues with multiprocessing on AWS Lambda
with patch("mpire.WorkerPool", MagicMock()), patch("mpire.async_result.AsyncResult", MagicMock()):
with open(local_func_filename, "rb") as f:
function, args, kwargs = pickle.load(f)
sys.modules["mpire"] = MagicMock()

result = function(*args, **kwargs)
with open(local_result_filename, "wb") as f:
pickle.dump(result, f)
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)

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

0 comments on commit 88fef2a

Please sign in to comment.