Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ccd8e34

Browse files
committed
asyncio doc: socket.socketpair() is not available on Windows yet
1 parent 04e6df3 commit ccd8e34

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

Doc/library/asyncio-eventloop.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,13 @@ Wait until a file descriptor received some data using the
676676
:meth:`BaseEventLoop.add_reader` method and then close the event loop::
677677

678678
import asyncio
679-
import socket
679+
try:
680+
from socket import socketpair
681+
except ImportError:
682+
from asyncio.windows_utils import socketpair
680683

681684
# Create a pair of connected file descriptors
682-
rsock, wsock = socket.socketpair()
685+
rsock, wsock = socketpair()
683686
loop = asyncio.get_event_loop()
684687

685688
def reader():

Doc/library/asyncio-protocol.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,13 @@ Wait until a socket receives data using the
521521
the event loop ::
522522

523523
import asyncio
524-
import socket
524+
try:
525+
from socket import socketpair
526+
except ImportError:
527+
from asyncio.windows_utils import socketpair
525528

526529
# Create a pair of connected sockets
527-
rsock, wsock = socket.socketpair()
530+
rsock, wsock = socketpair()
528531
loop = asyncio.get_event_loop()
529532

530533
class MyProtocol(asyncio.Protocol):

Doc/library/asyncio-stream.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,14 @@ Coroutine waiting until a socket receives data using the
296296
:func:`open_connection` function::
297297

298298
import asyncio
299-
import socket
299+
try:
300+
from socket import socketpair
301+
except ImportError:
302+
from asyncio.windows_utils import socketpair
300303

301304
def wait_for_data(loop):
302305
# Create a pair of connected sockets
303-
rsock, wsock = socket.socketpair()
306+
rsock, wsock = socketpair()
304307

305308
# Register the open socket to wait for data
306309
reader, writer = yield from asyncio.open_connection(sock=rsock, loop=loop)

0 commit comments

Comments
 (0)