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

MOTOR-1087 motor_asyncio freezes when using multiprocessing #196

Merged
merged 5 commits into from
Mar 16, 2023

Conversation

juliusgeo
Copy link
Contributor

No description provided.

Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

if hasattr(os, "register_at_fork"):
# This will run in the same thread as the fork was called.
# If we fork in a critical region on the same thread, it should break.
# This is fine since we would never call fork directly from a critical region.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this comment trying to say?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this over from Ben's PR, which had this comment for all of the register_at_fork calls. I can remove if you think it is not valuable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't think its valuable. The problem is that it's only describing what after_in_child does. If there was a comment here it should explain why we call it, eg "ThreadPoolExecutor is not fork safe, reinitialize it post fork."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now.

child_exec = parent_conn.recv()
self.assertIsNot(child_exec, init_exec)
passed, msg = parent_conn.recv()
self.assertTrue(passed, msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of testing that the id of asyncio._EXECUTOR changes, we should test that a new motor client can actually be used in the child process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.



if hasattr(os, "register_at_fork"):
# We need this to make sure that creating new clients in threads doesn't deadlock.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

threads -> subprocesses

@juliusgeo juliusgeo merged commit 935c543 into mongodb:master Mar 16, 2023
blink1073 pushed a commit that referenced this pull request Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants