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.

Author asvetlov
Recipients Ben.Darnell, aeros, asvetlov, minrk, serhiy.storchaka, xtreak, yselivanov
Date 2021-12-01.09:05:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1638349549.01.0.750794048264.issue39529@roundup.psfhosted.org>
In-reply-to
Content
IMHO, asyncio.set_event_loop() and policy.get_event_loop()/policy.set_event_loop() are not deprecated by oversight.

In IPython, I think you could use new_event_loop() for getting a new loop instance.
Then, save the loop reference somewhere as a direct attribute, threading.local or ContextVar.
Calling loop.run_until_complete() looks pretty normal in your situation.

At my job, we have Runner class, the basic usage is:
with Runner() as runner:
    runner.run(async_func())

The implementation is pretty close to asyncio.run() but runner.run(...) can be called multiple times. Async context manager interface is responsible for resource closing.

Maybe I should extract the implementation into a third-party library, I've found this concept useful for CLI applications at least.
History
Date User Action Args
2021-12-01 09:05:49asvetlovsetrecipients: + asvetlov, Ben.Darnell, serhiy.storchaka, yselivanov, minrk, xtreak, aeros
2021-12-01 09:05:49asvetlovsetmessageid: <1638349549.01.0.750794048264.issue39529@roundup.psfhosted.org>
2021-12-01 09:05:49asvetlovlinkissue39529 messages
2021-12-01 09:05:48asvetlovcreate