From d12f0365d5dcd58e3460909b99587fddfad108a7 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sat, 18 Jan 2014 14:11:44 +0000 Subject: [PATCH] Handle all-zeros KeyError for removed torrents alerts --- deluge/core/torrentmanager.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 03b0900ad..0606c0edf 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -947,7 +947,7 @@ class TorrentManager(component.Component): log.debug("on_alert_torrent_checked") try: torrent = self.torrents[str(alert.handle.info_hash())] - except RuntimeError: + except (RuntimeError, KeyError): return # Check to see if we're forcing a recheck and set it back to paused @@ -966,7 +966,7 @@ class TorrentManager(component.Component): log.debug("on_alert_tracker_reply: %s", decode_string(alert.message())) try: torrent = self.torrents[str(alert.handle.info_hash())] - except RuntimeError: + except (RuntimeError, KeyError): return # Set the tracker status for the torrent @@ -984,7 +984,7 @@ class TorrentManager(component.Component): log.debug("on_alert_tracker_announce") try: torrent = self.torrents[str(alert.handle.info_hash())] - except RuntimeError: + except (RuntimeError, KeyError): return # Set the tracker status for the torrent @@ -995,7 +995,7 @@ class TorrentManager(component.Component): log.debug("on_alert_tracker_warning") try: torrent = self.torrents[str(alert.handle.info_hash())] - except RuntimeError: + except (RuntimeError, KeyError): return tracker_status = 'Warning: %s' % decode_string(alert.message()) # Set the tracker status for the torrent @@ -1006,7 +1006,7 @@ class TorrentManager(component.Component): log.debug("on_alert_tracker_error") try: torrent = self.torrents[str(alert.handle.info_hash())] - except RuntimeError: + except (RuntimeError, KeyError): return tracker_status = "Error: %s" % decode_string(alert.msg) torrent.set_tracker_status(tracker_status) @@ -1016,7 +1016,7 @@ class TorrentManager(component.Component): log.debug("on_alert_storage_moved") try: torrent = self.torrents[str(alert.handle.info_hash())] - except RuntimeError: + except (RuntimeError, KeyError): return torrent.set_save_path(os.path.normpath(alert.handle.save_path())) torrent.set_move_completed(False) @@ -1114,7 +1114,7 @@ class TorrentManager(component.Component): log.debug("on_alert_metadata_received") try: torrent = self.torrents[str(alert.handle.info_hash())] - except RuntimeError: + except (RuntimeError, KeyError): return torrent.on_metadata_received() @@ -1123,7 +1123,7 @@ class TorrentManager(component.Component): log.debug("on_alert_file_error: %s", decode_string(alert.message())) try: torrent = self.torrents[str(alert.handle.info_hash())] - except RuntimeError: + except (RuntimeError, KeyError): return torrent.update_state() @@ -1136,8 +1136,8 @@ class TorrentManager(component.Component): torrent_id = str(alert.handle.info_hash()) except RuntimeError: return - component.get("EventManager").emit( - TorrentFileCompletedEvent(torrent_id, alert.index)) + if torrent_id in self.torrents: + component.get("EventManager").emit(TorrentFileCompletedEvent(torrent_id, alert.index)) def on_alert_state_update(self, alert): """Alert handler for libtorrent state_update_alert