From 0eed84d0b2fe144850a082feb339187bd98a4817 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 23 Jan 2021 15:41:13 +0100 Subject: xmlstream: handle done tasks in wait_until and handle other loops properly --- slixmpp/xmlstream/xmlstream.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index 6b890729..c8f797ac 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -1142,9 +1142,15 @@ class XMLStream(asyncio.BaseProtocol): :param int timeout: Timeout """ fut = asyncio.Future() + def result_handler(event_data): + if not fut.done(): + fut.set_result(event_data) + else: + log.debug("Future registered on event '%s' was alredy done", event) + self.add_event_handler( event, - fut.set_result, + result_handler, disposable=True, ) - return await asyncio.wait_for(fut, timeout) + return await asyncio.wait_for(fut, timeout, loop=self.loop) -- cgit v1.2.3