Skip to content

Commit 87d4deb

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver
2 parents e039381 + cb89061 commit 87d4deb

File tree

6 files changed

+47
-9
lines changed

6 files changed

+47
-9
lines changed

.github/workflows/release-python.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
permissions:
7373
id-token: write
7474
contents: write
75+
attestations: write
7576
security-events: write
7677
steps:
7778
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2

.pre-commit-config.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,11 @@ repos:
7575
stages: [manual]
7676

7777
- repo: https://github.com/sirosen/check-jsonschema
78-
rev: 0.27.0
78+
rev: 0.29.0
7979
hooks:
80-
- id: check-jsonschema
81-
name: "Check GitHub Workflows"
82-
files: ^\.github/workflows/
83-
types: [yaml]
84-
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]
85-
stages: [manual]
80+
- id: check-github-workflows
81+
- id: check-github-actions
82+
- id: check-dependabot
8683

8784
- repo: https://github.com/ariebovenberg/slotscheck
8885
rev: v0.19.0

pymongo/asynchronous/periodic_executor.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ def __repr__(self) -> str:
6565
return f"<{self.__class__.__name__}(name={self._name}) object at 0x{id(self):x}>"
6666

6767
def _run_async(self) -> None:
68-
asyncio.run(self._run()) # type: ignore[func-returns-value]
68+
# The default asyncio loop implementation on Windows
69+
# has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240)
70+
# We explicitly use a different loop implementation here to prevent that issue
71+
if sys.platform == "win32":
72+
loop = asyncio.SelectorEventLoop()
73+
try:
74+
loop.run_until_complete(self._run()) # type: ignore[func-returns-value]
75+
finally:
76+
loop.close()
77+
else:
78+
asyncio.run(self._run()) # type: ignore[func-returns-value]
6979

7080
def open(self) -> None:
7181
"""Start. Multiple calls have no effect.

pymongo/synchronous/periodic_executor.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ def __repr__(self) -> str:
6565
return f"<{self.__class__.__name__}(name={self._name}) object at 0x{id(self):x}>"
6666

6767
def _run_async(self) -> None:
68-
asyncio.run(self._run()) # type: ignore[func-returns-value]
68+
# The default asyncio loop implementation on Windows
69+
# has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240)
70+
# We explicitly use a different loop implementation here to prevent that issue
71+
if sys.platform == "win32":
72+
loop = asyncio.SelectorEventLoop()
73+
try:
74+
loop.run_until_complete(self._run()) # type: ignore[func-returns-value]
75+
finally:
76+
loop.close()
77+
else:
78+
asyncio.run(self._run()) # type: ignore[func-returns-value]
6979

7080
def open(self) -> None:
7181
"""Start. Multiple calls have no effect.

test/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@
7979

8080
_IS_SYNC = True
8181

82+
# The default asyncio loop implementation on Windows
83+
# has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240)
84+
# We explicitly use a different loop implementation here to prevent that issue
85+
if (
86+
not _IS_SYNC
87+
and sys.platform == "win32"
88+
and asyncio.get_event_loop_policy() == asyncio.WindowsProactorEventLoopPolicy
89+
):
90+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore[attr-defined]
91+
8292

8393
class ClientContext:
8494
client: MongoClient

test/asynchronous/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@
7979

8080
_IS_SYNC = False
8181

82+
# The default asyncio loop implementation on Windows
83+
# has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240)
84+
# We explicitly use a different loop implementation here to prevent that issue
85+
if (
86+
not _IS_SYNC
87+
and sys.platform == "win32"
88+
and asyncio.get_event_loop_policy() == asyncio.WindowsProactorEventLoopPolicy
89+
):
90+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore[attr-defined]
91+
8292

8393
class AsyncClientContext:
8494
client: AsyncMongoClient

0 commit comments

Comments
 (0)