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

Skip to content

Commit c717c73

Browse files
hniksicmiss-islington
authored andcommitted
bpo-38178: Don't explicitly pass "loop" to EchoClientProtocol. (GH-16159)
https://bugs.python.org/issue38178
1 parent 6e27a0d commit c717c73

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

Doc/library/asyncio-protocol.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,8 @@ data, and waits until the connection is closed::
767767

768768

769769
class EchoClientProtocol(asyncio.Protocol):
770-
def __init__(self, message, on_con_lost, loop):
770+
def __init__(self, message, on_con_lost):
771771
self.message = message
772-
self.loop = loop
773772
self.on_con_lost = on_con_lost
774773

775774
def connection_made(self, transport):
@@ -869,11 +868,10 @@ method, sends data and closes the transport when it receives the answer::
869868

870869

871870
class EchoClientProtocol:
872-
def __init__(self, message, loop):
871+
def __init__(self, message, on_con_lost):
873872
self.message = message
874-
self.loop = loop
875873
self.transport = None
876-
self.on_con_lost = loop.create_future()
874+
self.on_con_lost = on_con_lost
877875

878876
def connection_made(self, transport):
879877
self.transport = transport
@@ -899,13 +897,15 @@ method, sends data and closes the transport when it receives the answer::
899897
# low-level APIs.
900898
loop = asyncio.get_running_loop()
901899

900+
on_con_lost = loop.create_future()
902901
message = "Hello World!"
902+
903903
transport, protocol = await loop.create_datagram_endpoint(
904-
lambda: EchoClientProtocol(message, loop),
904+
lambda: EchoClientProtocol(message, on_con_lost),
905905
remote_addr=('127.0.0.1', 9999))
906906

907907
try:
908-
await protocol.on_con_lost
908+
await on_con_lost
909909
finally:
910910
transport.close()
911911

0 commit comments

Comments
 (0)