Skip to content

Commit

Permalink
[#1330] [Core] Fix pausing and resuming session
Browse files Browse the repository at this point in the history
 * The paused state of torrents is now correctly stored on shutdown if the session is paused.
 * core.pause_all_torrents now uses libtorrent session.pause and resume_all_torrents also refreshes
   all torrents' state. This fixes only torrents that changed state being updated so queued torrents
   would be incorrectly displayed as paused.
 * Scheduler and Blocklist now use updated core methods rather than calling libtorrent directly.
  • Loading branch information
cas-- committed Sep 28, 2015
1 parent eab7850 commit 7315255
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
13 changes: 8 additions & 5 deletions deluge/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,18 @@ def move_storage(self, torrent_ids, dest):
@export
def pause_all_torrents(self):
"""Pause all torrents in the session"""
for torrent in self.torrentmanager.torrents.values():
torrent.pause()
if not self.session.is_paused():
self.session.pause()
component.get("EventManager").emit(SessionPausedEvent())

@export
def resume_all_torrents(self):
"""Resume all torrents in the session"""
for torrent in self.torrentmanager.torrents.values():
torrent.resume()
component.get("EventManager").emit(SessionResumedEvent())
if self.session.is_paused():
self.session.resume()
for torrent in self.torrentmanager.torrents.values():
torrent.update_state()
component.get("EventManager").emit(SessionResumedEvent())

@export
def resume_torrent(self, torrent_ids):
Expand Down
7 changes: 5 additions & 2 deletions deluge/core/torrentmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,12 @@ def save_state(self):
state = TorrentManagerState()
# Create the state for each Torrent and append to the list
for torrent in self.torrents.values():
paused = False
if torrent.state == "Paused":
if self.session.is_paused():
paused = torrent.handle.is_paused()
elif torrent.state == "Paused":
paused = True
else:
paused = False

torrent_state = TorrentState(
torrent.torrent_id,
Expand Down
4 changes: 2 additions & 2 deletions deluge/plugins/blocklist/blocklist/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,12 @@ def auto_detect(self, blocklist):

def pause_session(self):
if not self.core.session.is_paused():
self.core.session.pause()
self.core.pause_all_torrents()
self.need_to_resume_session = True
else:
self.need_to_resume_session = False

def resume_session(self, result):
self.core.session.resume()
self.core.resume_all_torrents()
self.need_to_resume_session = False
return result
6 changes: 3 additions & 3 deletions deluge/plugins/scheduler/scheduler/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __apply_set_functions(self):
for setting in CONTROLLED_SETTINGS:
core_config.apply_set_functions(setting)
# Resume the session if necessary
component.get("Core").session.resume()
component.get("Core").resume_all_torrents()

def do_schedule(self, timer=True):
"""
Expand All @@ -153,10 +153,10 @@ def do_schedule(self, timer=True):
settings.active_seeds = self.config["low_active_up"]
session.set_settings(settings)
# Resume the session if necessary
component.get("Core").session.resume()
component.get("Core").resume_all_torrents()
elif state == "Red":
# This is Red (Stop), so pause the libtorrent session
component.get("Core").session.pause()
component.get("Core").pause_all_torrents()

if state != self.state:
# The state has changed since last update so we need to emit an event
Expand Down

0 comments on commit 7315255

Please sign in to comment.