aio-libs / aiosmtpd

A reimplementation of the Python stdlib smtpd.py based on asyncio.
https://aiosmtpd.aio-libs.org
Apache License 2.0
319 stars 96 forks source link

Do not call `asyncio.get_event_loop()` if no existing event loop #353

Closed pepoluan closed 1 year ago

pepoluan commented 1 year ago

As described in https://docs.python.org/3/library/asyncio-eventloop.html , directly calling asyncio.get_event_loop() raises DeprecationWarning if no event loop is already running. The behavior of get_event_loop() was changed in Python 3.10.

Up to Python 3.9, get_event_loop() will silently create an event loop with no warnings.

It seems that in Python 3.10 and 3.11, get_event_loop() will still create an event loop, but a DeprecationWarning is raised.

The get_event_loop() behavior will change completely in Python 3.12, no longer creating an event loop but will raise an Error instead.

We must parse the code and ensure that get_event_loop() expecting an implicit event loop creation are removed from the code.