Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c717c73f
Commit
c717c73f
authored
Sep 15, 2019
by
Hrvoje Nikšić
Committed by
Miss Islington (bot)
Sep 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-38178: Don't explicitly pass "loop" to EchoClientProtocol. (GH-16159)
https://bugs.python.org/issue38178
parent
6e27a0d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
Doc/library/asyncio-protocol.rst
Doc/library/asyncio-protocol.rst
+7
-7
No files found.
Doc/library/asyncio-protocol.rst
View file @
c717c73f
...
@@ -767,9 +767,8 @@ data, and waits until the connection is closed::
...
@@ -767,9 +767,8 @@ data, and waits until the connection is closed::
class EchoClientProtocol(asyncio.Protocol):
class EchoClientProtocol(asyncio.Protocol):
def __init__(self, message, on_con_lost
, loop
):
def __init__(self, message, on_con_lost):
self.message = message
self.message = message
self.loop = loop
self.on_con_lost = on_con_lost
self.on_con_lost = on_con_lost
def connection_made(self, transport):
def connection_made(self, transport):
...
@@ -869,11 +868,10 @@ method, sends data and closes the transport when it receives the answer::
...
@@ -869,11 +868,10 @@ method, sends data and closes the transport when it receives the answer::
class EchoClientProtocol:
class EchoClientProtocol:
def __init__(self, message,
loop
):
def __init__(self, message,
on_con_lost
):
self.message = message
self.message = message
self.loop = loop
self.transport = None
self.transport = None
self.on_con_lost =
loop.create_future()
self.on_con_lost =
on_con_lost
def connection_made(self, transport):
def connection_made(self, transport):
self.transport = transport
self.transport = transport
...
@@ -899,13 +897,15 @@ method, sends data and closes the transport when it receives the answer::
...
@@ -899,13 +897,15 @@ method, sends data and closes the transport when it receives the answer::
# low-level APIs.
# low-level APIs.
loop = asyncio.get_running_loop()
loop = asyncio.get_running_loop()
on_con_lost = loop.create_future()
message = "Hello World!"
message = "Hello World!"
transport, protocol = await loop.create_datagram_endpoint(
transport, protocol = await loop.create_datagram_endpoint(
lambda: EchoClientProtocol(message,
loop
),
lambda: EchoClientProtocol(message,
on_con_lost
),
remote_addr=('127.0.0.1', 9999))
remote_addr=('127.0.0.1', 9999))
try:
try:
await
protocol.
on_con_lost
await on_con_lost
finally:
finally:
transport.close()
transport.close()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment