PYTHON-4537 - Use selector asyncio loop on windows tests (#1748)
This commit is contained in:
parent
afd0b6f84c
commit
cb89061627
@ -65,7 +65,17 @@ class PeriodicExecutor:
|
||||
return f"<{self.__class__.__name__}(name={self._name}) object at 0x{id(self):x}>"
|
||||
|
||||
def _run_async(self) -> None:
|
||||
asyncio.run(self._run()) # type: ignore[func-returns-value]
|
||||
# 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 sys.platform == "win32":
|
||||
loop = asyncio.SelectorEventLoop()
|
||||
try:
|
||||
loop.run_until_complete(self._run()) # type: ignore[func-returns-value]
|
||||
finally:
|
||||
loop.close()
|
||||
else:
|
||||
asyncio.run(self._run()) # type: ignore[func-returns-value]
|
||||
|
||||
def open(self) -> None:
|
||||
"""Start. Multiple calls have no effect.
|
||||
|
||||
@ -65,7 +65,17 @@ class PeriodicExecutor:
|
||||
return f"<{self.__class__.__name__}(name={self._name}) object at 0x{id(self):x}>"
|
||||
|
||||
def _run_async(self) -> None:
|
||||
asyncio.run(self._run()) # type: ignore[func-returns-value]
|
||||
# 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 sys.platform == "win32":
|
||||
loop = asyncio.SelectorEventLoop()
|
||||
try:
|
||||
loop.run_until_complete(self._run()) # type: ignore[func-returns-value]
|
||||
finally:
|
||||
loop.close()
|
||||
else:
|
||||
asyncio.run(self._run()) # type: ignore[func-returns-value]
|
||||
|
||||
def open(self) -> None:
|
||||
"""Start. Multiple calls have no effect.
|
||||
|
||||
@ -79,6 +79,16 @@ from pymongo.synchronous.mongo_client import MongoClient
|
||||
|
||||
_IS_SYNC = True
|
||||
|
||||
# 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"
|
||||
and asyncio.get_event_loop_policy() == asyncio.WindowsProactorEventLoopPolicy
|
||||
):
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore[attr-defined]
|
||||
|
||||
|
||||
class ClientContext:
|
||||
client: MongoClient
|
||||
|
||||
@ -79,6 +79,16 @@ from pymongo.ssl_support import HAVE_SSL, _ssl # type:ignore[attr-defined]
|
||||
|
||||
_IS_SYNC = False
|
||||
|
||||
# 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"
|
||||
and asyncio.get_event_loop_policy() == asyncio.WindowsProactorEventLoopPolicy
|
||||
):
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore[attr-defined]
|
||||
|
||||
|
||||
class AsyncClientContext:
|
||||
client: AsyncMongoClient
|
||||
|
||||
Loading…
Reference in New Issue
Block a user