-
Notifications
You must be signed in to change notification settings - Fork 26
Conversation
Hum, I would prefer to pass loop explicitly. Later, users can learn how to get ride of the explicit loop parameter. Maybe add a section to explain that? |
-1 On Fri, Oct 21, 2016, 15:17 Vincent Michel notifications@github.com wrote:
|
I don't really see how that makes the code more reliable.
So if the first call to Now the default policy defines "context" as the current thread, meaning On the other hand, passing the loop explicitly everywhere might generate some issues, see asyncio issue #390 for instance. On linux, the policy is responsible for providing the child subprocess watcher. So if one chooses to go explicit, the loop should also be attached explicitly:
That is fine to do for testing in depth a library such as aiohttp, but it seems overly complicated for simple user code. |
You should discuss that on async-sig and/or tulip mailing list.
|
@asvetlov
|
I changed my mind, I'm now in favor of omiting the loop parameter. It seems like even for asyncio "experts" passing explicitly the loop or not is not a simple choice, so I suggest to write a section to explain when the loop parameter can be omitted, and explain the advantage of passing explicitly the loop parameter. I understand that in most cases, the loop parameter can be omitted, it helps for readability (shorter code). The only advantage is a micro optimization to avoid the cost of the get_event_loop() call? So maybe explain that the parameter should be omitted, but if you need extreme performance, you can pass it explicitly? I like methods like loop.create_task() because it avoids the need of a question: the loop is passed explicitly and the code remains simple and obvious :-) |
Good to me. |
e4d2ad5
to
9bed2f6
Compare
This PR has been widely updated to promote the use of a main coroutine. This practice is re-enforced by asyncio PR #452: Make get_event_loop() return the current loop if called from coroutines/callbacks. This naturally causes most of the loop references to disappear, since all asyncio objects are created within the context of a coroutine. Most of the examples now end up with the following block: loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close In python 3.6, it might be replaced with asyncio.run(main()) This PR also fixes the warnings when building the documentation (9bed2f6). @pya I made separated commits for the webscraper, since this part of the update is pretty heavy: I tried to make sure the webscraper page still makes sense, but let me know I forgot anything, or if you don't agree with some of the modifications. |
9bed2f6
to
96d87c5
Compare
I shut down the project: #33 |
This PR removes all the explicit loop arguments for consistency.
Another solution is to pass the loop explicitly everywhere but this would make the examples more complicated. This approach is sometimes described as a good practice, though I would argue the good practice is to rely on
get_event_loop()
unless you have a good reason not to (especially for user code).Partially related: Issue #9
EDIT: This PR has been widely updated to promote the use of a main coroutine.
This practice is re-enforced by asyncio PR #452: Make get_event_loop() return the current loop if called from coroutines/callbacks. This naturally causes most of the loop references to disappear, since all asyncio objects are created in the context of a coroutine. Most of the examples now end up with the following block:
In python 3.6, it might be replaced with
asyncio.run
(given PR #465 is merged):This PR also fixes the warnings when building the documentation.