Release locks properly

This commit is contained in:
Giuseppe Guerra 2017-07-28 22:46:24 +02:00
parent eab8bee828
commit 8c3fc6842d

View File

@ -103,27 +103,30 @@ class token:
:param bytes_: (packet) bytes to enqueue :param bytes_: (packet) bytes to enqueue
""" """
# Acquire the buffer lock try:
self.bufferLock.acquire() # Acquire the buffer lock
self.bufferLock.acquire()
# Never enqueue for IRC clients or Foka # Never enqueue for IRC clients or Foka
if self.irc or self.userID < 999: if self.irc or self.userID < 999:
return return
# Avoid memory leaks # Avoid memory leaks
if len(bytes_) < 10 * 10 ** 6: if len(bytes_) < 10 * 10 ** 6:
self.queue += bytes_ self.queue += bytes_
else: else:
log.warning("{}'s packets buffer is above 10M!! Lost some data!".format(self.username)) log.warning("{}'s packets buffer is above 10M!! Lost some data!".format(self.username))
finally:
# Release the buffer lock # Release the buffer lock
self.bufferLock.release() self.bufferLock.release()
def resetQueue(self): def resetQueue(self):
"""Resets the queue. Call when enqueued packets have been sent""" """Resets the queue. Call when enqueued packets have been sent"""
self.bufferLock.acquire() try:
self.queue = bytes() self.bufferLock.acquire()
self.bufferLock.release() self.queue = bytes()
finally:
self.bufferLock.release()
def joinChannel(self, channelObject): def joinChannel(self, channelObject):
""" """