This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Remove explicit "loop" argument from EchoClientProtocol example
Type: Stage: resolved
Components: asyncio, Documentation Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: asvetlov, docs@python, hniksic, miss-islington, rhettinger, vstinner, yselivanov
Priority: normal Keywords: patch

Created on 2019-09-15 15:17 by hniksic, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16159 merged hniksic, 2019-09-15 15:19
PR 16161 merged miss-islington, 2019-09-15 17:06
PR 16162 merged miss-islington, 2019-09-15 17:06
Messages (10)
msg352478 - (view) Author: Hrvoje Nikšić (hniksic) * Date: 2019-09-15 15:17
The EchoClientProtocol example receives a "loop" argument, which is not used at all in the TCP example, and is used to create a future in the UDP example. In modern asyncio code the explicit loop arguments are no longer used since the loop can always be obtained with get_running_loop().

The proposed patch makes the UDP example consistent with the TCP one (by having the constructor accept the on_con_lost future) and removes the loop argument from both.
msg352480 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-09-15 16:44
The was added originally by Victor and Yuri in c7edffdddd3 and 7c7605ff113
msg352482 - (view) Author: miss-islington (miss-islington) Date: 2019-09-15 17:06
New changeset c717c73fa33a2f3591442059eaf6e7a673e2c725 by Miss Islington (bot) (Hrvoje Nikšić) in branch 'master':
bpo-38178: Don't explicitly pass "loop" to EchoClientProtocol. (GH-16159)
https://github.com/python/cpython/commit/c717c73fa33a2f3591442059eaf6e7a673e2c725
msg352483 - (view) Author: miss-islington (miss-islington) Date: 2019-09-15 17:12
New changeset 701c4886bb0e19ad5ed8c8f556f65ab8597841e7 by Miss Islington (bot) in branch '3.7':
bpo-38178: Don't explicitly pass "loop" to EchoClientProtocol. (GH-16159)
https://github.com/python/cpython/commit/701c4886bb0e19ad5ed8c8f556f65ab8597841e7
msg352484 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-09-15 17:12
Hrvoje, thanks for fixing this.

Next time, please involve the people who originally wrote the code.  They are both still active.  If they made mistakes, it helps them to know about it.  If they had a specific intent for the code example, it allows them to make sure the objectives are still being achieved.
msg352485 - (view) Author: miss-islington (miss-islington) Date: 2019-09-15 17:13
New changeset 1cd6e926d30552056457820a682c1c361ee0f3ff by Miss Islington (bot) in branch '3.8':
bpo-38178: Don't explicitly pass "loop" to EchoClientProtocol. (GH-16159)
https://github.com/python/cpython/commit/1cd6e926d30552056457820a682c1c361ee0f3ff
msg352487 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-09-15 17:23
Thanks Hrvoje!
msg352488 - (view) Author: Hrvoje Nikšić (hniksic) * Date: 2019-09-15 17:28
Raymond, no problem; I guess I assumed that the authors are following the bug tracker (or have possibly moved on and are inactive).

I also had reason to believe the change to be non-controversial, since it is in line with Yury's own recommendations, e.g. from his 2018 EuroPython presentation (slide 14):

https://speakerdeck.com/1st1/asyncio-today-and-tomorrow

In any case, I am happy that the pull request has been processed and accepted so quickly - thanks everyone for the great work!
msg352491 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-09-15 17:51
Raymond, sorry if I was so quick in applying.
The patch is very trivial and obvious.
I am pretty sure that Yuri and Victor approve it.

The PR doesn't fix a mistake, the code is still valid.
But we all changed our mind what is the loop role, should it be explicitly passed everywhere or not, etc.

At the time of the example creation explicit loop was safer, after Python 3.5.3 bugfx release the implicit loop became the idiomatic solution.

We use the implicit loop everywhere, 3.8 raises DeprecationWarning for passing the loop into certain API calls.
The PR just changes the example to follow our own recommendations.
msg352529 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-16 08:15
> In modern asyncio code the explicit loop arguments are no longer used since the loop can always be obtained with get_running_loop().

Yeah, the trend changed. Around Python 3.4, passing explicitly loop was preferred for best performances.

Since that time, the code to get the current loop has been optimized, and the new trend is to make the loop implicit to make the code more readable.

--

When I wrote the doc, self.loop.stop() was called explicitly:

https://docs.python.org/3.5/library/asyncio-protocol.html#tcp-echo-client-protocol

It seems like the example has been modified to add a new "on_con_lost" Future.

--

Anyway, thanks Hrvoje Nikšić for your contribution ;-)
History
Date User Action Args
2022-04-11 14:59:20adminsetgithub: 82359
2019-09-16 08:15:20vstinnersetmessages: + msg352529
2019-09-15 17:51:08asvetlovsetmessages: + msg352491
2019-09-15 17:28:18hniksicsetmessages: + msg352488
2019-09-15 17:23:47asvetlovsetstatus: open -> closed
resolution: fixed
messages: + msg352487

stage: patch review -> resolved
2019-09-15 17:13:37miss-islingtonsetmessages: + msg352485
2019-09-15 17:12:24rhettingersetmessages: + msg352484
2019-09-15 17:12:15miss-islingtonsetmessages: + msg352483
2019-09-15 17:06:23miss-islingtonsetpull_requests: + pull_request15772
2019-09-15 17:06:16miss-islingtonsetpull_requests: + pull_request15771
2019-09-15 17:06:04miss-islingtonsetnosy: + miss-islington
messages: + msg352482
2019-09-15 16:44:32rhettingersetnosy: + rhettinger, vstinner
messages: + msg352480
2019-09-15 15:19:36hniksicsetkeywords: + patch
stage: patch review
pull_requests: + pull_request15769
2019-09-15 15:17:34hniksiccreate