From 124100fcf529dc0041676791b64aaf50cee12563 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 29 Dec 2015 11:36:13 -0800 Subject: [PATCH] classes: actually, loop schedulePing only when connection_thread is alive Related to #152. Probably still not perfect, but shutdowns are somewhat faster than they were before. --- classes.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/classes.py b/classes.py index 1dd6e96..49bec0a 100644 --- a/classes.py +++ b/classes.py @@ -398,14 +398,23 @@ class Irc(): def schedulePing(self): """Schedules periodic pings in a loop.""" - while not self.aborted.is_set(): + if not self.connection_thread: + # We're running in a non-threaded context, abort. + log.debug('(%s) Ignoring schedulePing() request since threading ' + 'seems to be disabled.', self.name) + return + + # Only run this loop for the duration where the listener thread + # is active! The goal is to stop the ping threads as soon as possible + # after the relevant listeners die. + while self.connection_thread.is_alive(): log.debug('(%s) Ping sent at %s', self.name, time.time()) self.proto.pingServer() # Sleep for the time (frequency) between pings. time.sleep(self.pingfreq) - log.debug('(%s) Canceling ping_thread at %s due to self.aborted being set.', self.name, time.time()) + log.debug('(%s) Canceling ping_thread at %s due to listener thread stopping.', self.name, time.time()) def spawnMain(self): """Spawns the main PyLink client."""