From 2a67a31120ade3664cc3bf49e04367ca27caf21f Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Wed, 7 Dec 2011 22:16:58 -0800 Subject: [PATCH] Prevent hang when terminating during delayed connection. --- sleekxmpp/xmlstream/xmlstream.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index 8fcf2b5..1a0b624 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -398,7 +398,16 @@ class XMLStream(object): delay = min(self.reconnect_delay * 2, self.reconnect_max_delay) delay = random.normalvariate(delay, delay * 0.1) log.debug('Waiting %s seconds before connecting.', delay) - time.sleep(delay) + elapsed = 0 + try: + while elapsed < delay and not self.stop.is_set(): + time.sleep(0.1) + except KeyboardInterrupt: + self.stop.set() + return False + except SystemExit: + self.stop.set() + return False if self.use_proxy: connected = self._connect_proxy()