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

Option to Skip Monkey Patching with LOCUST_SKIP_MONKEY_PATCH #2765

Merged
merged 1 commit into from
Jun 21, 2024

Conversation

andrewbaldwin44
Copy link
Collaborator

Proposal

  1. Add a condition to the __init__.py that will skip monkey patching when LOCUST_SKIP_MONKEY_PATCH is set
  2. Update use-as-lib to document disabling monkey patching

Tested

Tested using Locust as a lib with boto3

Fixes #2250

@cyberw
Copy link
Collaborator

cyberw commented Jun 21, 2024

Cool! Would it work if we also automatically skipped monkey patching if it has already been done, like this?

if not monkey.is_module_patched("thread"):
    monkey.patch_all()
else:
    print("Skipping monkey patching, because it had already been performed")

@andrewbaldwin44
Copy link
Collaborator Author

That was the first thing I tried, unfortunately it doesn't work. I went with this solution since I saw both yourself and Heyman suggested it in another thread

@cyberw cyberw merged commit 932f6c3 into locustio:master Jun 21, 2024
14 checks passed
@MykhailoKhil
Copy link

Hey @andrewbaldwin44 @cyberw
I have faced a problem with Boto3 and tried this solution.
However when I put env var to skip
LOCUST_SKIP_MONKEY_PATCH = 1

got a error on worker [2024-07-26 11:59:51,200] ip-10-0-108-168/WARNING/locust.runners: Failed to connect to master locust-master.152.master-locust-performance.com:5557, retry 61/60.
and master
2024-07-26T12:02:41 [2024-07-26 12:02:41,460] ip-10-0-107-88/INFO/root: Waiting for workers to be ready, 0 of 1 connected

939 | 2024-07-26T12:02:42 [2024-07-26 12:02:42,460] ip-10-0-107-88/ERROR/locust.main: Gave up waiting for workers to connect
940 | 2024-07-26T12:02:42 [2024-07-26 12:02:42,461] ip-10-0-107-88/INFO/locust.runners: Worker ip-10-0-108-168.ec2.internal_3fe6ad348afb4e8b9c88db6b603c0ed2 (index 0) reported as ready. 1 workers connected.
941 | 2024-07-26T12:02:42 [2024-07-26 12:02:42,462] ip-10-0-107-88/INFO/locust.runners: Worker ip-10-0-115-214.ec2.internal_a084b8a1159b4696a3f3682413d3e026 (index 1) reported as ready. 2 workers connected.

I use AWS ECS. master and worker goes as independent services. Communication between them via private rout53.
It works okay without any problem if not put LOCUST_SKIP_MONKEY_PATCH env var
do you have any ideas why workers could not connect if we skip monkey.patch_all() ?
Thanks!

@cyberw
Copy link
Collaborator

cyberw commented Jul 27, 2024

LOCUST_SKIP_MONKEY_PATCH is just used to avoid monkey patching twice. I'm guessing in your case it was never done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mass monkeypatching leads to boto3 incompatibility and infinite recursion in pytest (when used as lib)
3 participants