Use pop_alerts() instead of looping with pop_alert

This saves CPU cycles on a busy session.
This commit is contained in:
Kai Huuhko 2015-04-15 14:44:03 +03:00
parent 9d83e78579
commit 18299f202c
1 changed files with 4 additions and 9 deletions

View File

@ -1,7 +1,7 @@
#
# Epour - A bittorrent client using EFL and libtorrent
#
# Copyright 2012-2014 Kai Huuhko <kai.huuhko@gmail.com>
# Copyright 2012-2015 Kai Huuhko <kai.huuhko@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -393,7 +393,7 @@ class AlertManager(object):
self.timer = Timer(self.update_interval, self.update)
def callback_add(self, alert_type, cb, *args, **kwargs):
if not alert_type in self.alerts:
if alert_type not in self.alerts:
self.alerts[alert_type] = []
self.alerts[alert_type].append((cb, args, kwargs))
@ -405,7 +405,7 @@ class AlertManager(object):
def signal(self, a):
a_name = type(a).__name__
if not a_name in self.alerts:
if a_name not in self.alerts:
self.log.debug("No handler: {} | {}".format(a_name, a))
return
@ -416,13 +416,8 @@ class AlertManager(object):
self.log.exception("Exception while handling alerts")
def update(self):
# TODO: Use pop_alerts()
#self.log.debug("Alerts TICK")
while 1:
a = self.session.pop_alert()
if not a:
break
for a in self.session.pop_alerts():
self.signal(a)
return True