Ask HN: Ways to deal with Python 3.11 breaking change to asyncio
AFAICT 3.11 requires your code to call asyncio.run(), whereas earlier versions (for some definition of "earlier") required you to inject your coroutines and then call loop.run_forever().
Basically it smells to me like this is going to require two distinct main()s. This is ugly. How do I make it not butt ugly and minimize the general odor?
10 comments
[ 4.2 ms ] story [ 35.0 ms ] threadFrom what I can see so far asyncio.gather() would seem to be the canonical refactor.
I'm not sure that I'm down with the philosophy of the loop stopping running AT ALL unless I ask for it. I've got long-running processes. I spew stack traces from within coroutines, and if the situation is dire enough I call stop() myself.
I always thought that being able to leave coroutines in the queue when the loop isn't running was a feature, not a bug.
Can't tell from that remark whether you're asking or telling...
edit: that is to say, asyncio.run() may be required now but the method of injecting coroutines and then doing run_forever was definitely not required before. Asyncio.run was available before 3.11.
Carefully preserved punctuation there: the full stop. If you run asyncio.start_server(), today, on 3.11, it does not return an awaitable.
Suppose I run asyncio.start_server() and I want it to run forever. What am I supposed to asyncio.gather()) on without making stuff up?
[Edit] Production code or it didn't happen.
I stumbled on this as something that works:
Which demonstrates that the following is, ahem, sleight of hand: although supposedly it guarantees some cleanup which I don't care about. Both options respond identically (at least with 3.11.0) to ^C.I reiterate that serve_forever() is not in 3.6.