From b87f68fcb69b53469fa814e3fd43cce1eda1eb5c Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Wed, 12 Mar 2008 06:30:49 +0000 Subject: [PATCH] Fix issue where we try to handle lt alerts for torrents that have not had a Torrent object created for them yet. --- deluge/core/alertmanager.py | 11 +++-------- deluge/core/torrentmanager.py | 8 +++++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/deluge/core/alertmanager.py b/deluge/core/alertmanager.py index 4d1be6e03..2f171f759 100644 --- a/deluge/core/alertmanager.py +++ b/deluge/core/alertmanager.py @@ -42,21 +42,16 @@ from deluge.log import LOG as log class AlertManager(component.Component): def __init__(self, session): log.debug("AlertManager initialized..") - component.Component.__init__(self, "AlertManager") + component.Component.__init__(self, "AlertManager", interval=50) self.session = session self.session.set_severity_level(lt.alert.severity_levels.info) # handlers is a dictionary of lists {"alert_type": [handler1,h2,..]} self.handlers = {} - def start(self): - # Handle the alerts every 50 milliseconds - self.timer = gobject.timeout_add(50, self.handle_alerts) - - def stop(self): - gobject.source_remove(self.timer) + def update(self): + self.handle_alerts() def shutdown(self): - self.stop() del self.session del self.handlers diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 4f73716ae..c63b558c5 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -239,6 +239,9 @@ class TorrentManager(component.Component): else: storage_mode = lt.storage_mode_t(1) + # We need to pause the AlertManager momentarily to prevent alerts + # for this torrent being generated before a Torrent object is created. + component.pause("AlertManager") try: handle = self.session.add_torrent( lt.torrent_info(filedump), @@ -251,12 +254,15 @@ class TorrentManager(component.Component): if not handle or not handle.is_valid(): # The torrent was not added to the session + component.resume("AlertManager") return None # Create a Torrent object torrent = Torrent(filename, handle, options["compact_allocation"], options["download_location"], total_uploaded, trackers) - + + component.resume("AlertManager") + # Add the torrent object to the dictionary self.torrents[torrent.torrent_id] = torrent