Skip to content

PYTHON-4537 - Use selector asyncio loop on windows tests #1748

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

Merged
merged 8 commits into from
Jul 26, 2024

Conversation

NoahStapp
Copy link
Contributor

No description provided.

# has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240)
# We explicitly use a different loop implementation here to prevent that issue
if not _IS_SYNC and sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore[attr-defined]
Copy link
Member

Choose a reason for hiding this comment

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

We can't call asyncio.set_event_loop_policy since that has global side effects. Instead we need to explicitly create our on loop, possibly only when the default would be the ProactorEventLoop.

@NoahStapp NoahStapp requested a review from ShaneHarvey July 25, 2024 22:34
and sys.platform == "win32"
and asyncio.get_event_loop_policy() == asyncio.WindowsProactorEventLoopPolicy
):
loop = asyncio.WindowsSelectorEventLoopPolicy().new_event_loop() # type: ignore[attr-defined]
Copy link
Member

Choose a reason for hiding this comment

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

How about we just always use WindowsSelectorEventLoopPolicy on windows for now. I'm worried the WindowsProactorEventLoopPolicy check won't work for custom policies that use the proactor loop.

Copy link
Member

Choose a reason for hiding this comment

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

Let's also call asyncio.SelectorEventLoop() directly.

@NoahStapp NoahStapp requested a review from ShaneHarvey July 25, 2024 22:56
# The default asyncio loop implementation on Windows
# has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240)
# We explicitly use a different loop implementation here to prevent that issue
if not _IS_SYNC and sys.platform == "win32":
Copy link
Member

Choose a reason for hiding this comment

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

We can remove not _IS_SYNC here.

@NoahStapp NoahStapp requested a review from ShaneHarvey July 26, 2024 14:26
@NoahStapp NoahStapp merged commit cb89061 into mongodb:master Jul 26, 2024
33 checks passed
@NoahStapp NoahStapp deleted the PYTHON-4537-3 branch July 26, 2024 16:49
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.

2 participants