Fixed an issue related to high CPU Usage when Streaming is enabled. Closes #220

This commit is contained in:
Manuel Cortez 2018-06-06 11:14:42 -05:00
parent 9847f7ad01
commit a2cb4ba889
2 changed files with 7 additions and 6 deletions

View File

@ -127,12 +127,11 @@ class Controller(object):
pub.subscribe(self.manage_item_in_list, "item-in-list")
pub.subscribe(self.on_tweet_deleted, "tweet-deleted")
pub.subscribe(self.manage_stream_errors, "stream-error")
pub.subscribe(self.restart_streams, "restart-streams")
# pub.subscribe(self.restart_streams, "restart-streams")
def bind_other_events(self):
""" Binds the local application events with their functions."""
log.debug("Binding other application events...")
pub.subscribe(self.restart_streams_, "restart_streams")
pub.subscribe(self.buffer_title_changed, "buffer-title-changed")
pub.subscribe(self.manage_sent_dm, "sent-dm")
widgetUtils.connect_event(self.view, widgetUtils.CLOSE_EVENT, self.exit_)
@ -266,6 +265,8 @@ class Controller(object):
self.checker_function.start()
self.save_db = RepeatingTimer(300, self.save_data_in_db)
self.save_db.start()
self.update_buffers_function = RepeatingTimer(60, self.update_buffers)
self.update_buffers_function.start()
def start(self):
""" Starts all buffer objects. Loads their items."""
@ -1587,9 +1588,9 @@ class Controller(object):
if hasattr(self, action):
getattr(self, action)()
def restart_streams_(self, session):
def update_buffers(self):
for i in self.buffers[:]:
if i.session != None and i.session.session_id == session:
if i.session != None and i.session.is_logged == True:
try:
i.start_stream()
except TwythonAuthError:
@ -1664,4 +1665,4 @@ class Controller(object):
def save_data_in_db(self):
for i in session_.sessions:
session_.sessions[i].shelve()
session_.sessions[i].shelve()

View File

@ -395,13 +395,13 @@ class Session(object):
self.logged = False
self.twitter = twitter.twitter.twitter()
self.login(False)
pub.sendMessage("restart_streams", session=self.session_id)
if self.reconnection_function_active == True: return
self.reconnection_function_active = True
if not hasattr(self, "main_stream") or not application.streaming_lives():
self.get_main_stream()
if not hasattr(self, "timelinesStream") or application.streaming_lives():
self.get_timelines()
self.counter = 0
self.reconnection_function_active = False
if hasattr(self, "timelinesStream") and not hasattr(self.timelinesStream, "friends"):
self.add_friends()