From 0707786057a77788d9a2801474ed9fdccc9b7b3c Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 9 Feb 2025 13:39:57 +0100 Subject: [PATCH] xmlstream: "cleanl" create a new event loop if none is set Relates to #3542 --- slixmpp/xmlstream/xmlstream.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index 60928999..90985858 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -375,7 +375,23 @@ class XMLStream(asyncio.BaseProtocol): @property def loop(self) -> AbstractEventLoop: 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 @loop.setter