[Python-ideas] Add hooks to asyncio lifecycle

Michel Desmoulin desmoulinmichel at gmail.com
Sat Jun 9 09:31:08 EDT 2018



Le 09/06/2018 à 12:33, Andrew Svetlov a écrit :
> If we consistently apply the idea of hook for internal python structure
> modification too many things should be changed. Import
> machinery, tracemalloc, profilers/tracers, name it.
> If your code (I still don't see the real-life example) wants to check a
> policy change -- just do it.
> 
> # on initialization
> policy = asyncio.get_event_loop_policy()
> 
> # somewhere in code
> if policy is not asyncio.get_event_loop_policy():
>     raise RuntimeError("Policy was changed")

You need to repeat this check everywhere because nothing guaranty a code
hasn't change it after the check.

While a call back allow you to catch it every time.

You can set either raise, warn, monkey patch, disable features, etc.


More information about the Python-ideas mailing list