<div dir="ltr">Hold on.<br>aiohttp doesn't suffer from hooks absence. Moreover, I don't see how these hooks could be utilized by aiohttp. Gunicorn workers are not imported and instantiated by user code, they are imported by gunicorn using a command line parameter.<br><br>Please choose a different use case as the proof of your request.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 6, 2018 at 1:41 PM Michel Desmoulin <<a href="mailto:desmoulinmichel@gmail.com">desmoulinmichel@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi Yuri,<br>
<br>
> <br>
> I actually want to propose to reduce policies API surface by<br>
> deprecating and then removing "set_child_watcher()" methods.  Besides,<br>
> there are many other higher priority To-Do items for asyncio in 3.8,<br>
> like implementing Trio's nursery-like objects and cancellation scopes<br>
> or fixing tracebacks in Tasks.<br>
> <br>
> That said, the above is my "IMO".  And in your email you haven't<br>
> actually provided clear scenarios that could be solved by adding<br>
> "event loop hooks" to asyncio.  So I have a few questions for you:<br>
> <br>
> - Do you have real-life examples of libraries that abuse policies in<br>
> some weird ways?<br>
<br>
It's not abuse, it's just regular use of a documented feature, but a<br>
very potent feature with deep consequences.<br>
<br>
> - Are those libraries popular?<br>
<br>
aiothttp comes to mind. But the fact is, I think people explicitly avoid<br>
using policies and custom loops because they know that they can be<br>
swapped and you can't make it a hard requirement since they can be<br>
swapped under your node.<br>
<br>
> - What's the actual problem they try to solve by using policies?<br>
<br>
e.g:<br>
<a href="https://github.com/aio-libs/aiohttp/blob/53828229a13dc72137f430abc7a0c469678f3dd6/aiohttp/worker.py" rel="noreferrer" target="_blank">https://github.com/aio-libs/aiohttp/blob/53828229a13dc72137f430abc7a0c469678f3dd6/aiohttp/worker.py</a><br>
<br>
> - What problem are you trying to solve in your code that uses policies?<br>
<br>
I have tried to create an abstraction that creates an uvloop if it<br>
exists, or a regular loop otherwise, or integrated it to the twisted<br>
reactor or the trio event loop if it's loaded.<br>
<br>
I want to abstract that from the user, so I tried to put that in a<br>
policy. But that's dangerous since it can be changed at any time, so I<br>
gave up on it and made it explicit. Of course, if the user misses that<br>
in the doc (hopefully, it's an company internal code so they should be<br>
trained), it will be a bummer to debug.<br>
<br>
Another example is the proof of concept of nurseries we talked about on<br>
twitter:<br>
<br>
<a href="https://0bin.net/paste/V5KyhAg-2i5EOyoK#dzBvhdCVeFy8Q2xNcxXyqwtyQFgkxlKI3u5QG0buIcT" rel="noreferrer" target="_blank">https://0bin.net/paste/V5KyhAg-2i5EOyoK#dzBvhdCVeFy8Q2xNcxXyqwtyQFgkxlKI3u5QG0buIcT</a><br>
<br>
Yet another one, with a custom loop this time:<br>
<br>
I want to provide a fail fast mode for code using loop.run_forever. The<br>
goal is to make it crashes when an uncaught exception occurs instead of<br>
just log it in the console to ease debugging in a local machine.<br>
<br>
Of course it would be best to use run_until_complete instead but you<br>
don't always get to choose.<br>
<br>
So we set a task factory on the loop. But, of course, you lose<br>
everything if something changes the loop on the fly, which my code has<br>
no idea has happened.<br>
<br>
Another use case is to just log that the loop / policy has changed in<br>
debug mode. It's always something I want to know anyway, because it has<br>
consequences on my entire program since those are pretty fundamental<br>
components.<br>
<br>
> - Why do you think this isn't a documentation/tutorial issue?> - Can you list 2-3 clear examples where having hooks would benefit an<br>
> average asyncio user?<br>
<br>
The best documentation is the one you don't need to write. But if I'm<br>
being honest, I'd like to have it despite having a good warning in the<br>
documentation.<br>
<br>
When you run Django's manage.py runserver, it will check your code for a<br>
lot of common issues and raise a warning or an exception, letting you<br>
know what to do.<br>
<br>
With those hooks, I could check if a policy or a loop is changed, and if<br>
some things in my code depends on a policy or a loop, I can do the same<br>
and raise a warning or an exception.<br>
<br>
This benefit the users because they get the info exactly in context, and<br>
not just rely on them reading the doc, understanding it, remembering it<br>
and applying it.<br>
<br>
And that benefits the framework writers because that's less support, and<br>
less bug reports to deal with.<br>
<br>
Using asyncio is scary and mysterious enough for a lot of people, so I<br>
want to make the experience as natural as possible. I don't want people<br>
to have to read my doc and learn what event loops and policies are for<br>
basic usage. It's too much. But on the other hand, I do want them to be<br>
able to debug a problem if the loop or policy is swapped.<br>
<br>
> <br>
> Thank you,<br>
> Yury<br>
<br>
Thank you too<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Thanks,</div>Andrew Svetlov</div></div>