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

Skip to content

Commit 5d359cc

Browse files
hniksicmiss-islington
authored andcommitted
bpo-38192: Fix remaining passing of "loop" in the protocol examples (GH-16202)
See https://bugs.python.org/issue38192 . https://bugs.python.org/issue38192
1 parent f669581 commit 5d359cc

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Doc/library/asyncio-protocol.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ data, and waits until the connection is closed::
792792
message = 'Hello World!'
793793

794794
transport, protocol = await loop.create_connection(
795-
lambda: EchoClientProtocol(message, on_con_lost, loop),
795+
lambda: EchoClientProtocol(message, on_con_lost),
796796
'127.0.0.1', 8888)
797797

798798
# Wait until the protocol signals that the connection
@@ -870,8 +870,8 @@ method, sends data and closes the transport when it receives the answer::
870870
class EchoClientProtocol:
871871
def __init__(self, message, on_con_lost):
872872
self.message = message
873-
self.transport = None
874873
self.on_con_lost = on_con_lost
874+
self.transport = None
875875

876876
def connection_made(self, transport):
877877
self.transport = transport
@@ -927,9 +927,9 @@ Wait until a socket receives data using the
927927

928928
class MyProtocol(asyncio.Protocol):
929929

930-
def __init__(self, loop):
930+
def __init__(self, on_con_lost):
931931
self.transport = None
932-
self.on_con_lost = loop.create_future()
932+
self.on_con_lost = on_con_lost
933933

934934
def connection_made(self, transport):
935935
self.transport = transport
@@ -950,13 +950,14 @@ Wait until a socket receives data using the
950950
# Get a reference to the event loop as we plan to use
951951
# low-level APIs.
952952
loop = asyncio.get_running_loop()
953+
on_con_lost = loop.create_future()
953954

954955
# Create a pair of connected sockets
955956
rsock, wsock = socket.socketpair()
956957

957958
# Register the socket to wait for data.
958959
transport, protocol = await loop.create_connection(
959-
lambda: MyProtocol(loop), sock=rsock)
960+
lambda: MyProtocol(on_con_lost), sock=rsock)
960961

961962
# Simulate the reception of data from the network.
962963
loop.call_soon(wsock.send, 'abc'.encode())

0 commit comments

Comments
 (0)