asyncio doc: socket.socketpair() is not available on Windows yet
This commit is contained in:
parent
04e6df330d
commit
ccd8e34508
|
@ -676,10 +676,13 @@ Wait until a file descriptor received some data using the
|
||||||
:meth:`BaseEventLoop.add_reader` method and then close the event loop::
|
:meth:`BaseEventLoop.add_reader` method and then close the event loop::
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import socket
|
try:
|
||||||
|
from socket import socketpair
|
||||||
|
except ImportError:
|
||||||
|
from asyncio.windows_utils import socketpair
|
||||||
|
|
||||||
# Create a pair of connected file descriptors
|
# Create a pair of connected file descriptors
|
||||||
rsock, wsock = socket.socketpair()
|
rsock, wsock = socketpair()
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
def reader():
|
def reader():
|
||||||
|
|
|
@ -521,10 +521,13 @@ Wait until a socket receives data using the
|
||||||
the event loop ::
|
the event loop ::
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import socket
|
try:
|
||||||
|
from socket import socketpair
|
||||||
|
except ImportError:
|
||||||
|
from asyncio.windows_utils import socketpair
|
||||||
|
|
||||||
# Create a pair of connected sockets
|
# Create a pair of connected sockets
|
||||||
rsock, wsock = socket.socketpair()
|
rsock, wsock = socketpair()
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
class MyProtocol(asyncio.Protocol):
|
class MyProtocol(asyncio.Protocol):
|
||||||
|
|
|
@ -296,11 +296,14 @@ Coroutine waiting until a socket receives data using the
|
||||||
:func:`open_connection` function::
|
:func:`open_connection` function::
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import socket
|
try:
|
||||||
|
from socket import socketpair
|
||||||
|
except ImportError:
|
||||||
|
from asyncio.windows_utils import socketpair
|
||||||
|
|
||||||
def wait_for_data(loop):
|
def wait_for_data(loop):
|
||||||
# Create a pair of connected sockets
|
# Create a pair of connected sockets
|
||||||
rsock, wsock = socket.socketpair()
|
rsock, wsock = socketpair()
|
||||||
|
|
||||||
# Register the open socket to wait for data
|
# Register the open socket to wait for data
|
||||||
reader, writer = yield from asyncio.open_connection(sock=rsock, loop=loop)
|
reader, writer = yield from asyncio.open_connection(sock=rsock, loop=loop)
|
||||||
|
|
Loading…
Reference in New Issue