Skip to content

Commit c22ae84

Browse files
committed
PYTHON-5405 Use legacy wait_for_read cancellation approach on Windows
1 parent 24e9da6 commit c22ae84

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pymongo/network_layer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import asyncio
1919
import collections
2020
import errno
21+
import os
2122
import socket
2223
import struct
2324
import sys
@@ -286,6 +287,7 @@ async def _async_socket_receive(
286287

287288

288289
_PYPY = "PyPy" in sys.version
290+
_WINDOWS = os.name == "nt"
289291

290292

291293
def wait_for_read(conn: Connection, deadline: Optional[float]) -> None:
@@ -337,7 +339,8 @@ def receive_data(conn: Connection, length: int, deadline: Optional[float]) -> me
337339
while bytes_read < length:
338340
try:
339341
# Use the legacy wait_for_read cancellation approach on PyPy due to PYTHON-5011.
340-
if _PYPY:
342+
# also use it on Windows due to PYTHON-5405
343+
if _PYPY or _WINDOWS:
341344
wait_for_read(conn, deadline)
342345
if _csot.get_timeout() and deadline is not None:
343346
conn.set_conn_timeout(max(deadline - time.monotonic(), 0))
@@ -359,6 +362,7 @@ def receive_data(conn: Connection, length: int, deadline: Optional[float]) -> me
359362
raise _OperationCancelled("operation cancelled") from None
360363
if (
361364
_PYPY
365+
or _WINDOWS
362366
or not conn.is_sdam
363367
and deadline is not None
364368
and deadline - time.monotonic() < 0

0 commit comments

Comments
 (0)