:meth:`BaseEventLoop.add_reader` method and then close the event loop::
import asyncio
- import socket
+ try:
+ from socket import socketpair
+ except ImportError:
+ from asyncio.windows_utils import socketpair
# Create a pair of connected file descriptors
- rsock, wsock = socket.socketpair()
+ rsock, wsock = socketpair()
loop = asyncio.get_event_loop()
def reader():
the event loop ::
import asyncio
- import socket
+ try:
+ from socket import socketpair
+ except ImportError:
+ from asyncio.windows_utils import socketpair
# Create a pair of connected sockets
- rsock, wsock = socket.socketpair()
+ rsock, wsock = socketpair()
loop = asyncio.get_event_loop()
class MyProtocol(asyncio.Protocol):
:func:`open_connection` function::
import asyncio
- import socket
+ try:
+ from socket import socketpair
+ except ImportError:
+ from asyncio.windows_utils import socketpair
def wait_for_data(loop):
# Create a pair of connected sockets
- rsock, wsock = socket.socketpair()
+ rsock, wsock = socketpair()
# Register the open socket to wait for data
reader, writer = yield from asyncio.open_connection(sock=rsock, loop=loop)