Cleaner consumers

This commit is contained in:
nemunaire 2014-07-17 12:01:04 +02:00
parent e5741ce1cb
commit a8ce37a372
2 changed files with 11 additions and 9 deletions

View File

@ -258,15 +258,15 @@ class IRCServer(server.Server):
print ("\033[1;35mWarning:\033[0m Nemubot talks to himself: %s" % msg) print ("\033[1;35mWarning:\033[0m Nemubot talks to himself: %s" % msg)
traceback.print_stack() traceback.print_stack()
if line is not None and channel is not None: if line is not None and channel is not None:
if self.s is None: if self.s is None:
print ("\033[1;35mWarning:\033[0m Attempt to send message on a non connected server: %s: %s" % (self.id, line)) print ("\033[1;35mWarning:\033[0m Attempt to send message on a non connected server: %s: %s" % (self.id, line))
traceback.print_stack() traceback.print_stack()
elif len(line) < 442: elif len(line) < 442:
self.s.send (("%s %s :%s%s" % (cmd, channel, line, endl)).encode ()) self.s.send (("%s %s :%s%s" % (cmd, channel, line, endl)).encode ())
else: else:
print ("\033[1;35mWarning:\033[0m Message truncated due to size (%d ; max : 442) : %s" % (len(line), line)) print ("\033[1;35mWarning:\033[0m Message truncated due to size (%d ; max : 442) : %s" % (len(line), line))
traceback.print_stack() traceback.print_stack()
self.s.send (("%s %s :%s%s" % (cmd, channel, line[0:442]+"...", endl)).encode ()) self.s.send (("%s %s :%s%s" % (cmd, channel, line[0:442]+"<…>", endl)).encode ())
def send_msg_usr(self, user, msg): def send_msg_usr(self, user, msg):
"""Send a message to a user instead of a channel""" """Send a message to a user instead of a channel"""

View File

@ -136,8 +136,10 @@ class Consumer(threading.Thread):
while not self.stop: while not self.stop:
stm = self.context.cnsr_queue.get(True, 20) stm = self.context.cnsr_queue.get(True, 20)
stm.run(self.context) stm.run(self.context)
self.context.cnsr_queue.task_done()
except queue.Empty: except queue.Empty:
pass pass
finally: finally:
self.context.cnsr_thrd_size -= 2 self.context.cnsr_thrd_size -= 2
self.context.cnsr_thrd.remove(self)