'apply the policy to the torrents stored'

def apply(self, torrents, max_active, force=False):

    sorted_torrents = sorted([torrent for torrent in torrents.itervalues() if self.key_check(torrent)], key=self.key, reverse=self.reverse)
    torrents_start = []
    for torrent in sorted_torrents[:max_active]:
        if (not self.session.get_download(torrent['metainfo'].get_infohash())):
            torrents_start.append(torrent)
    torrents_stop = []
    for torrent in sorted_torrents[max_active:]:
        if self.session.get_download(torrent['metainfo'].get_infohash()):
            torrents_stop.append(torrent)
    if force:
        return (torrents_start, torrents_stop)
    if ((not isinstance(self, RandomPolicy)) and (((not torrents_start) and (not torrents_stop)) or ((len(torrents_start) < (len(torrents) / 2)) and (len(torrents_start) < (max_active / 2))))):
        self._logger.error('Start    and    stop    torrent    list    are    empty.    Fallback    to    Random')
        (torrents_start, torrents_stop) = RandomPolicy(self.session).apply(torrents, max_active)
    return (torrents_start, torrents_stop)
