Fix issue with removing items while iterating through the self.state

dictionary.
This commit is contained in:
Andrew Resch 2008-01-13 08:32:46 +00:00
parent 0d793e7f89
commit 1de14a1ce0
1 changed files with 12 additions and 4 deletions

View File

@ -913,20 +913,23 @@ Space:") + " " + nice_free)
ret = None # We return new added unique ID(s), or None
no_space = False
to_remove = []
# Add torrents to core and unique_IDs
for torrent in self.state.torrents:
if not os.path.exists(torrent.filename):
print "Missing file: %s" % torrent.filename
del self.state.torrents[torrent]
to_remove.append(torrent)
continue
if torrent not in self.unique_IDs.values():
try:
unique_ID = deluge_core.add_torrent(torrent.filename,
torrent.save_dir,
torrent.compact)
except DelugeError, e:
del self.state.torrents[torrent]
raise e
except Exception, e:
print "Unable to add torrent: ", e
to_remove.append(torrent)
continue
ret = unique_ID
self.unique_IDs[unique_ID] = torrent
self.state.torrents[torrent] = unique_ID
@ -945,6 +948,11 @@ Space:") + " " + nice_free)
except:
pass
# Remove torrents from self.state because they were not added to the
# libtorrent session.
for torrent in to_remove:
del self.state.torrents[torrent]
# Remove torrents from core, unique_IDs and queue
to_delete = []
for unique_ID in self.unique_IDs.keys():