mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-05 17:43:37 +00:00
Add optional start and stop ping threads, during start, shutdown and saving providers.
This commit is contained in:
parent
2c2a5b175f
commit
9d9dee175f
3 changed files with 63 additions and 1 deletions
|
@ -86,6 +86,8 @@ subtitlesFinderScheduler = None
|
|||
# traktCheckerScheduler = None
|
||||
background_mapping_task = None
|
||||
|
||||
provider_ping_thread_pool = {}
|
||||
|
||||
showList = None
|
||||
UPDATE_SHOWS_ON_START = False
|
||||
SHOW_UPDATE_HOUR = 3
|
||||
|
@ -523,7 +525,8 @@ def initialize(console_logging=True):
|
|||
# global traktCheckerScheduler
|
||||
global recentSearchScheduler, backlogSearchScheduler, showUpdateScheduler, \
|
||||
versionCheckScheduler, showQueueScheduler, searchQueueScheduler, \
|
||||
properFinderScheduler, autoPostProcesserScheduler, subtitlesFinderScheduler, background_mapping_task
|
||||
properFinderScheduler, autoPostProcesserScheduler, subtitlesFinderScheduler, background_mapping_task, \
|
||||
provider_ping_thread_pool
|
||||
# Add Show Defaults
|
||||
global STATUS_DEFAULT, QUALITY_DEFAULT, SHOW_TAG_DEFAULT, FLATTEN_FOLDERS_DEFAULT, SUBTITLES_DEFAULT, \
|
||||
WANTED_BEGIN_DEFAULT, WANTED_LATEST_DEFAULT, SCENE_DEFAULT, ANIME_DEFAULT
|
||||
|
@ -1344,6 +1347,12 @@ def start():
|
|||
indexermapper.indexer_list = [i for i in indexerApi().all_indexers]
|
||||
background_mapping_task.start()
|
||||
|
||||
for p in providers.sortedProviderList():
|
||||
if p.is_active() and hasattr(p, 'ping'):
|
||||
provider_ping_thread_pool[p.get_id()] = threading.Thread(name='PING-PROVIDER %s' % p.get_id(),
|
||||
target=p.ping)
|
||||
provider_ping_thread_pool[p.get_id()].start()
|
||||
|
||||
for thread in enabled_schedulers(is_init=True):
|
||||
thread.start()
|
||||
|
||||
|
@ -1390,6 +1399,15 @@ def halt():
|
|||
except RuntimeError:
|
||||
pass
|
||||
|
||||
for p in provider_ping_thread_pool:
|
||||
provider_ping_thread_pool[p].stop = True
|
||||
|
||||
for p in provider_ping_thread_pool:
|
||||
try:
|
||||
provider_ping_thread_pool[p].join(10)
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
if ADBA_CONNECTION:
|
||||
try:
|
||||
ADBA_CONNECTION.logout()
|
||||
|
|
|
@ -26,6 +26,7 @@ import os
|
|||
import re
|
||||
import time
|
||||
import urlparse
|
||||
import threading
|
||||
from urllib import quote_plus
|
||||
import zlib
|
||||
from base64 import b16encode, b32decode
|
||||
|
@ -702,6 +703,19 @@ class GenericProvider:
|
|||
pass
|
||||
return long(math.ceil(value))
|
||||
|
||||
def _should_stop(self):
|
||||
if getattr(threading.currentThread(), 'stop', False):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _sleep_with_stop(self, t):
|
||||
t_l = t
|
||||
while t_l > 0:
|
||||
time.sleep(3)
|
||||
t_l -= 3
|
||||
if self._should_stop():
|
||||
return
|
||||
|
||||
|
||||
class NZBProvider(object, GenericProvider):
|
||||
|
||||
|
|
|
@ -5234,6 +5234,33 @@ class ConfigProviders(Config):
|
|||
|
||||
return '1'
|
||||
|
||||
def checkProvidersPing(self):
|
||||
for p in sickbeard.providers.sortedProviderList():
|
||||
if hasattr(p, 'ping'):
|
||||
if p.is_active() and (p.get_id() not in sickbeard.provider_ping_thread_pool or not sickbeard.provider_ping_thread_pool[p.get_id()].is_alive()):
|
||||
sickbeard.provider_ping_thread_pool[p.get_id()] = threading.Thread(name='PING-PROVIDER %s' %
|
||||
p.get_id(), target=p.ping)
|
||||
sickbeard.provider_ping_thread_pool[p.get_id()].start()
|
||||
elif not p.is_active() and p.get_id() in sickbeard.provider_ping_thread_pool:
|
||||
sickbeard.provider_ping_thread_pool[p.get_id()].stop = True
|
||||
try:
|
||||
sickbeard.provider_ping_thread_pool[p.get_id()].join(120)
|
||||
if not sickbeard.provider_ping_thread_pool[p.get_id()].is_alive():
|
||||
sickbeard.provider_ping_thread_pool.pop(p.get_id())
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
# stop removed providers
|
||||
prov = [n.get_id() for n in sickbeard.providers.sortedProviderList()]
|
||||
for p in [x for x in sickbeard.provider_ping_thread_pool if x not in prov]:
|
||||
sickbeard.provider_ping_thread_pool[p].stop = True
|
||||
try:
|
||||
sickbeard.provider_ping_thread_pool[p].join(120)
|
||||
if not sickbeard.provider_ping_thread_pool[p].is_alive():
|
||||
sickbeard.provider_ping_thread_pool.pop(p)
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
def saveProviders(self, newznab_string='', torrentrss_string='', provider_order=None, **kwargs):
|
||||
|
||||
results = []
|
||||
|
@ -5426,6 +5453,9 @@ class ConfigProviders(Config):
|
|||
|
||||
sickbeard.save_config()
|
||||
|
||||
cp = threading.Thread(name='Check-Ping-Providers', target=self.checkProvidersPing)
|
||||
cp.start()
|
||||
|
||||
if 0 < len(results):
|
||||
for x in results:
|
||||
logger.log(x, logger.ERROR)
|
||||
|
|
Loading…
Reference in a new issue