Fix issue with removing items while iterating through the self.state
dictionary.
This commit is contained in:
parent
0d793e7f89
commit
1de14a1ce0
16
src/core.py
16
src/core.py
|
@ -913,20 +913,23 @@ Space:") + " " + nice_free)
|
||||||
ret = None # We return new added unique ID(s), or None
|
ret = None # We return new added unique ID(s), or None
|
||||||
no_space = False
|
no_space = False
|
||||||
|
|
||||||
|
to_remove = []
|
||||||
# Add torrents to core and unique_IDs
|
# Add torrents to core and unique_IDs
|
||||||
for torrent in self.state.torrents:
|
for torrent in self.state.torrents:
|
||||||
if not os.path.exists(torrent.filename):
|
if not os.path.exists(torrent.filename):
|
||||||
print "Missing file: %s" % torrent.filename
|
print "Missing file: %s" % torrent.filename
|
||||||
del self.state.torrents[torrent]
|
to_remove.append(torrent)
|
||||||
continue
|
continue
|
||||||
if torrent not in self.unique_IDs.values():
|
if torrent not in self.unique_IDs.values():
|
||||||
try:
|
try:
|
||||||
unique_ID = deluge_core.add_torrent(torrent.filename,
|
unique_ID = deluge_core.add_torrent(torrent.filename,
|
||||||
torrent.save_dir,
|
torrent.save_dir,
|
||||||
torrent.compact)
|
torrent.compact)
|
||||||
except DelugeError, e:
|
except Exception, e:
|
||||||
del self.state.torrents[torrent]
|
print "Unable to add torrent: ", e
|
||||||
raise e
|
to_remove.append(torrent)
|
||||||
|
continue
|
||||||
|
|
||||||
ret = unique_ID
|
ret = unique_ID
|
||||||
self.unique_IDs[unique_ID] = torrent
|
self.unique_IDs[unique_ID] = torrent
|
||||||
self.state.torrents[torrent] = unique_ID
|
self.state.torrents[torrent] = unique_ID
|
||||||
|
@ -945,6 +948,11 @@ Space:") + " " + nice_free)
|
||||||
except:
|
except:
|
||||||
pass
|
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
|
# Remove torrents from core, unique_IDs and queue
|
||||||
to_delete = []
|
to_delete = []
|
||||||
for unique_ID in self.unique_IDs.keys():
|
for unique_ID in self.unique_IDs.keys():
|
||||||
|
|
Loading…
Reference in New Issue