xmlstream: "cleanl" create a new event loop if none is set

Relates to #3542
This commit is contained in:
mathieui 2025-02-09 13:39:57 +01:00
parent 1c762c6b25
commit 0707786057
No known key found for this signature in database
GPG Key ID: C59F84CEEFD616E3

View File

@ -375,7 +375,23 @@ class XMLStream(asyncio.BaseProtocol):
@property @property
def loop(self) -> AbstractEventLoop: def loop(self) -> AbstractEventLoop:
if self._loop is None: if self._loop is None:
self._loop = asyncio.get_event_loop() try:
with warnings.catch_warnings(category=DeprecationWarning):
warnings.simplefilter("ignore")
self._loop = asyncio.get_event_loop()
# We do not know what exception will be raised in the future
# instead of the warning
except Exception:
try:
current = asyncio.get_running_loop()
except RuntimeError:
current = None
if current is not None:
self._loop = current
else:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
self._loop = loop
return self._loop return self._loop
@loop.setter @loop.setter