mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
Irc: block when the queue is empty instead of needlessly polling it
Rework Irc.processQueue() to block when the queue is full, and abort if the item "None" is sent to it. To make sure that the None isn't caught by a full queue or pushed back by other elements, this modifies queue.Queue's underlying deque instance directly. Closes #459.
This commit is contained in:
parent
06d49f4433
commit
daa6593534
18
classes.py
18
classes.py
@ -179,14 +179,12 @@ class Irc(utils.DeprecatedAttributesObject):
|
|||||||
while True:
|
while True:
|
||||||
throttle_time = self.serverdata.get('throttle_time', 0.005)
|
throttle_time = self.serverdata.get('throttle_time', 0.005)
|
||||||
if not self.aborted.wait(throttle_time):
|
if not self.aborted.wait(throttle_time):
|
||||||
try:
|
data = self.queue.get()
|
||||||
data = self.queue.get_nowait()
|
if data is None:
|
||||||
|
log.debug('(%s) Stopping queue thread due to getting None as item', self.name)
|
||||||
|
break
|
||||||
|
elif data:
|
||||||
self._send(data)
|
self._send(data)
|
||||||
except queue.Empty:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
log.debug('(%s) Stopping queue thread as aborted is set', self.name)
|
|
||||||
break
|
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
"""
|
"""
|
||||||
@ -396,6 +394,12 @@ class Irc(utils.DeprecatedAttributesObject):
|
|||||||
|
|
||||||
self.socket.close()
|
self.socket.close()
|
||||||
|
|
||||||
|
# Stop the queue thread.
|
||||||
|
if self.queue:
|
||||||
|
# XXX: queue.Queue.queue isn't actually documented, so this is probably not reliable in the long run.
|
||||||
|
self.queue.queue.appendleft(None)
|
||||||
|
|
||||||
|
# Stop the ping timer.
|
||||||
if self.pingTimer:
|
if self.pingTimer:
|
||||||
log.debug('(%s) Canceling pingTimer at %s due to disconnect() call', self.name, time.time())
|
log.debug('(%s) Canceling pingTimer at %s due to disconnect() call', self.name, time.time())
|
||||||
self.pingTimer.cancel()
|
self.pingTimer.cancel()
|
||||||
|
Loading…
Reference in New Issue
Block a user