Commit d590b016 authored by echel0n's avatar echel0n
Browse files

Migrated upnp client from threaded object to scheduler job, resolves shutdown/restart problems

parent 69cee253
# Changelog
- * c9b0780 - 2018-08-19: Misc code cleanup
- * 85f4ff8 - 2018-08-19: Migrated upnp client from threaded object to scheduler job, resolves shutdown/restart problems
- * 69cee25 - 2018-08-19: Misc code cleanup
- * a2aa340 - 2018-08-18: Pre-Release v9.3.56.dev28
- * 10de224 - 2018-08-18: Pre-Release v9.3.56.dev27
- * 8efa7cb - 2018-08-18: Fixed broken toggle buttons
......
......@@ -441,6 +441,16 @@ class Core(object):
id=self.subtitle_searcher.name
)
# add upnp client job
self.scheduler.add_job(
self.upnp_client.run,
IntervalTrigger(
seconds=self.upnp_client._nat_portmap_lifetime
),
name=self.upnp_client.name,
id=self.upnp_client.name
)
# start scheduler service
self.scheduler.start()
......@@ -449,10 +459,6 @@ class Core(object):
self.show_queue.start()
self.postprocessor_queue.start()
# start upnp client
if self.config.enable_upnp:
self.upnp_client.start()
# start webserver
self.wserver.start()
......@@ -467,10 +473,6 @@ class Core(object):
if self.wserver:
self.wserver.shutdown()
# shutdown upnp client
if self.upnp_client:
self.upnp_client.shutdown()
# shutdown show queue
if self.show_queue:
self.log.debug("Shutting down show queue")
......
......@@ -18,7 +18,6 @@
from __future__ import print_function, unicode_literals, with_statement
import threading
import time
from urlparse import urlparse
......@@ -29,33 +28,22 @@ import upnpclient
from sickrage.core.helpers import get_lan_ip
class UPNPClient(threading.Thread):
class UPNPClient(object):
_nat_portmap_lifetime = 30 * 60
def __init__(self):
super(UPNPClient, self).__init__(name='UPNP')
self.stop = threading.Event()
def __init__(self, *args, **kwargs):
self.name = "UPNP"
def run(self):
upnp_dev = self._discover_upnp_device()
if upnp_dev is not None:
if sickrage.app.config.enable_upnp:
self.add_nat_portmap()
self.refresh_nat_portmap()
def shutdown(self):
self.stop.set()
try:
self.join(1)
except:
pass
def refresh_nat_portmap(self):
"""Run an infinite loop refreshing our NAT port mapping.
On every iteration we configure the port mapping with a lifetime of 30 minutes and then
sleep for that long as well.
"""
while not self.stop.is_set():
while True:
time.sleep(self._nat_portmap_lifetime)
self.add_nat_portmap()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment