From 411edd094e095d8f8e1ccffe00eae56f9e06bd8b Mon Sep 17 00:00:00 2001 From: JackDandy Date: Thu, 15 Dec 2016 04:19:49 +0000 Subject: [PATCH] Change logger clean up to prevent lock during restart under pythonw. --- CHANGES.md | 1 + gui/slick/interfaces/default/inc_top.tmpl | 2 +- gui/slick/interfaces/default/restart.tmpl | 3 ++- gui/slick/js/restart.js | 8 ++++---- sickbeard/logger.py | 16 +++++++++------- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b7fe82c2..901706ff 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -247,6 +247,7 @@ * Change torrent provider links for bts, et, rarbg, tpb * Change IPT uri used for sanity check * Change PiSexy auth check +* Change logger clean up to prevent lock during restart under pythonw ### 0.11.16 (2016-10-16 17:30:00 UTC) diff --git a/gui/slick/interfaces/default/inc_top.tmpl b/gui/slick/interfaces/default/inc_top.tmpl index 5a8a5f16..eb173bc9 100644 --- a/gui/slick/interfaces/default/inc_top.tmpl +++ b/gui/slick/interfaces/default/inc_top.tmpl @@ -71,7 +71,7 @@ diff --git a/gui/slick/interfaces/default/restart.tmpl b/gui/slick/interfaces/default/restart.tmpl index 9aa75804..f7cfa9ab 100644 --- a/gui/slick/interfaces/default/restart.tmpl +++ b/gui/slick/interfaces/default/restart.tmpl @@ -42,7 +42,8 @@ Host: '$sg_host', Port: '$sg_port', Root: '$sg_root', - UseHttps: #echo ('!1', '!0')[False != $sg_use_https and 0 != $sg_use_https]# + UseHttps: #echo ('!1', '!0')[False != $sg_use_https and 0 != $sg_use_https]#, + PID: '$sbPID' }; //--> diff --git a/gui/slick/js/restart.js b/gui/slick/js/restart.js index 6acd3c50..9f579ae3 100644 --- a/gui/slick/js/restart.js +++ b/gui/slick/js/restart.js @@ -2,6 +2,7 @@ /** @namespace $.SickGear.Host */ /** @namespace $.SickGear.Port */ /** @namespace $.SickGear.UseHttps */ +/** @namespace $.SickGear.PID */ /** @namespace data.msg */ var sgRoot = $.SickGear.Root, @@ -10,24 +11,23 @@ var sgRoot = $.SickGear.Root, + (('' == sgRoot) ? $.SickGear.Port : location.port) + sgRoot, isAliveUrl = sgRoot + '/home/is_alive/', timeoutId; -$.SickGear.currentPid = ''; $.SickGear.numRestartWaits = 0; function is_alive() { timeoutId = 0; $.get(isAliveUrl, function(data) { - if ('nope' == data.msg.toString()) { + var resp = data.msg.toString(); + if ('nope' == resp) { // if initialising then just wait and try again $('#shut_down_message').find('.spinner,.hide-yes').removeClass(); $('#restart_message').removeClass(); setTimeout(is_alive, 100); - } else if ('' == $.SickGear.currentPid || $.SickGear.currentPid == data.msg) { + } else if (/undefined/i.test($.SickGear.PID) || $.SickGear.PID == resp) { // if this is before we've even shut down then just try again later - $.SickGear.currentPid = data.msg; setTimeout(is_alive, 100); } else { diff --git a/sickbeard/logger.py b/sickbeard/logger.py index 0e69849d..f39dc363 100644 --- a/sickbeard/logger.py +++ b/sickbeard/logger.py @@ -71,9 +71,9 @@ class SBRotatingLogHandler(object): handlers = [] if not handler: - handlers = [self.h_file] if None is not self.h_console: - handlers += [self.h_console] + handlers = [self.h_console] + handlers += [self.h_file] elif not isinstance(handler, list): handlers = [handler] @@ -81,8 +81,9 @@ class SBRotatingLogHandler(object): for logger_name in self.log_types + self.log_types_null: logging.getLogger(logger_name).removeHandler(handler) - handler.flush() - handler.close() + if type(handler) != type(logging.StreamHandler()): # check exact type, not an inherited instance + handler.flush() + handler.close() def init_logging(self, console_logging=False): @@ -103,9 +104,10 @@ class SBRotatingLogHandler(object): if self.console_logging: # get a console handler to output INFO or higher messages to sys.stderr h_console = logging.StreamHandler() - h_console.setLevel((logging.INFO, logging.DEBUG)[sickbeard.DEBUG]) - h_console.setFormatter(DispatchingFormatter(self._formatters(), logging.Formatter('%(message)s'), )) - self.h_console = h_console + if None is not h_console.stream: + h_console.setLevel((logging.INFO, logging.DEBUG)[sickbeard.DEBUG]) + h_console.setFormatter(DispatchingFormatter(self._formatters(), logging.Formatter('%(message)s'), )) + self.h_console = h_console # add the handler to the root logger for logger_name in self.log_types: