3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-28 05:29:25 +01:00

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.
This commit is contained in:
James Lu 2015-12-29 11:36:13 -08:00
parent 91f75e4d93
commit 124100fcf5

View File

@ -398,14 +398,23 @@ class Irc():
def schedulePing(self): def schedulePing(self):
"""Schedules periodic pings in a loop.""" """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()) log.debug('(%s) Ping sent at %s', self.name, time.time())
self.proto.pingServer() self.proto.pingServer()
# Sleep for the time (frequency) between pings. # Sleep for the time (frequency) between pings.
time.sleep(self.pingfreq) 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): def spawnMain(self):
"""Spawns the main PyLink client.""" """Spawns the main PyLink client."""