mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
Revert "classes: replace threading.Timer with normal threads for schedulePing"
This reverts commit 64bb646d1e
.
This commit is contained in:
parent
a7104dc01c
commit
a385bc32d9
36
classes.py
36
classes.py
@ -56,9 +56,9 @@ class Irc():
|
|||||||
# HACK: Don't thread if we're running tests.
|
# HACK: Don't thread if we're running tests.
|
||||||
self.connect()
|
self.connect()
|
||||||
else:
|
else:
|
||||||
self.connection_thread = threading.Thread(target=self.connect,
|
self.connection_thread = threading.Thread(target = self.connect)
|
||||||
name="Listener for %s" % self.name)
|
|
||||||
self.connection_thread.start()
|
self.connection_thread.start()
|
||||||
|
self.pingTimer = None
|
||||||
|
|
||||||
def initVars(self):
|
def initVars(self):
|
||||||
"""
|
"""
|
||||||
@ -128,8 +128,6 @@ class Irc():
|
|||||||
self.uplink = None
|
self.uplink = None
|
||||||
self.start_ts = int(time.time())
|
self.start_ts = int(time.time())
|
||||||
|
|
||||||
self.ping_thread = None
|
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
"""
|
"""
|
||||||
Runs the connect loop for the IRC object. This is usually called by
|
Runs the connect loop for the IRC object. This is usually called by
|
||||||
@ -213,14 +211,8 @@ class Irc():
|
|||||||
# and run the listen loop.
|
# and run the listen loop.
|
||||||
self.proto.connect()
|
self.proto.connect()
|
||||||
self.spawnMain()
|
self.spawnMain()
|
||||||
|
log.info('(%s) Starting ping schedulers....', self.name)
|
||||||
# Spawn the ping loop as a separate thread.
|
self.schedulePing()
|
||||||
log.info('(%s) Starting ping loop...', self.name)
|
|
||||||
self.ping_thread = threading.Thread(target=self.schedulePing,
|
|
||||||
name="Ping loop for %s" % self.name)
|
|
||||||
self.ping_thread.daemon = True
|
|
||||||
self.ping_thread.start()
|
|
||||||
|
|
||||||
log.info('(%s) Server ready; listening for data.', self.name)
|
log.info('(%s) Server ready; listening for data.', self.name)
|
||||||
self.run()
|
self.run()
|
||||||
else: # Configuration error :(
|
else: # Configuration error :(
|
||||||
@ -288,12 +280,13 @@ class Irc():
|
|||||||
|
|
||||||
def _disconnect(self):
|
def _disconnect(self):
|
||||||
"""Handle disconnects from the remote server."""
|
"""Handle disconnects from the remote server."""
|
||||||
|
log.debug('(%s) Canceling pingTimer at %s due to _disconnect() call', self.name, time.time())
|
||||||
self.connected.clear()
|
self.connected.clear()
|
||||||
try:
|
try:
|
||||||
self.socket.close()
|
self.socket.close()
|
||||||
|
self.pingTimer.cancel()
|
||||||
except: # Socket timed out during creation; ignore
|
except: # Socket timed out during creation; ignore
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Internal hook signifying that a network has disconnected.
|
# Internal hook signifying that a network has disconnected.
|
||||||
self.callHooks([None, 'PYLINK_DISCONNECT', {}])
|
self.callHooks([None, 'PYLINK_DISCONNECT', {}])
|
||||||
|
|
||||||
@ -397,15 +390,11 @@ class Irc():
|
|||||||
|
|
||||||
def schedulePing(self):
|
def schedulePing(self):
|
||||||
"""Schedules periodic pings in a loop."""
|
"""Schedules periodic pings in a loop."""
|
||||||
|
self.proto.pingServer()
|
||||||
while not self.aborted.is_set():
|
self.pingTimer = threading.Timer(self.pingfreq, self.schedulePing)
|
||||||
log.debug('(%s) Ping sent at %s', self.name, time.time())
|
self.pingTimer.daemon = True
|
||||||
self.proto.pingServer()
|
self.pingTimer.start()
|
||||||
|
log.debug('(%s) Ping scheduled at %s', self.name, time.time())
|
||||||
# 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())
|
|
||||||
|
|
||||||
def spawnMain(self):
|
def spawnMain(self):
|
||||||
"""Spawns the main PyLink client."""
|
"""Spawns the main PyLink client."""
|
||||||
@ -462,20 +451,17 @@ class IrcServer():
|
|||||||
name: The name of the server.
|
name: The name of the server.
|
||||||
internal: Whether the server is an internal PyLink PseudoServer.
|
internal: Whether the server is an internal PyLink PseudoServer.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, uplink, name, internal=False, desc="(None given)"):
|
def __init__(self, uplink, name, internal=False, desc="(None given)"):
|
||||||
self.uplink = uplink
|
self.uplink = uplink
|
||||||
self.users = set()
|
self.users = set()
|
||||||
self.internal = internal
|
self.internal = internal
|
||||||
self.name = name.lower()
|
self.name = name.lower()
|
||||||
self.desc = desc
|
self.desc = desc
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return repr(self.__dict__)
|
return repr(self.__dict__)
|
||||||
|
|
||||||
class IrcChannel():
|
class IrcChannel():
|
||||||
"""PyLink IRC channel class."""
|
"""PyLink IRC channel class."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Initialize variables, such as the topic, user list, TS, who's opped, etc.
|
# Initialize variables, such as the topic, user list, TS, who's opped, etc.
|
||||||
self.users = set()
|
self.users = set()
|
||||||
|
Loading…
Reference in New Issue
Block a user