From c3ce093ca0bae9a0c911e3254e6ef90891c096c0 Mon Sep 17 00:00:00 2001 From: Timofey Date: Mon, 28 Sep 2015 12:09:02 +0300 Subject: [PATCH 1/2] Added the check for a running server at the beginning of the script. --- tools/SiblingKiller.py | 15 +++++++++++++++ tools/testserver.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/SiblingKiller.py b/tools/SiblingKiller.py index 5ffe5a269c..d84330db5b 100644 --- a/tools/SiblingKiller.py +++ b/tools/SiblingKiller.py @@ -20,6 +20,7 @@ class SiblingKiller: self.__my_pid = self.my_process_id() self.port = port self.ping_timeout = ping_timeout + logging.debug("Sibling killer: my process id = {}".format(self.__my_pid)) def allow_serving(self): @@ -39,6 +40,15 @@ class SiblingKiller: If we are the process with the same name as ours and with the lowest process id, let's start serving and kill everyone else. """ + + if self.wait_for_server(): + self.__allow_serving = False + logging.debug("There is a server that is currently serving on our port... Disallowing to start a new one") + return + + logging.debug("There are no servers that are currently serving. Will try to kill our siblings.") + + sibs = self.siblings() for sibling in sibs: @@ -49,6 +59,7 @@ class SiblingKiller: if self.wait_for_server(): serving_pid = self.serving_process_id() if serving_pid: + logging.debug("There is a serving sibling with process id: {}".format(serving_pid)) self.kill(pids=map(lambda x: x != serving_pid, sibs)) self.__allow_serving = False return @@ -61,6 +72,7 @@ class SiblingKiller: def kill(self, pid=0, pids=list()): if not pid and not pids: + logging.debug("There are no siblings to kill") return if pid and pids: raise Exception("Use either one pid or multiple pids") @@ -142,6 +154,8 @@ class SiblingKiller: except (urllib2.URLError, socket.timeout): pass + logging.debug("Pinging returned html: {}".format(html)) + return html == "pong" @@ -166,6 +180,7 @@ class SiblingKiller: def exec_command(self, command): + logging.debug(">> {}".format(command)) p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE) output, err = p.communicate() p.wait() diff --git a/tools/testserver.py b/tools/testserver.py index d39edb029e..34736ffbf1 100644 --- a/tools/testserver.py +++ b/tools/testserver.py @@ -53,7 +53,7 @@ except: USE_TORNADO = False -logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO) +logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG) PORT = 34568 LIFESPAN = 180.0 # timeout for the self destruction timer - how much time From ba2b23a39c34599069feea55d4abf2c6055f71f3 Mon Sep 17 00:00:00 2001 From: Timofey Date: Mon, 28 Sep 2015 15:54:47 +0300 Subject: [PATCH 2/2] Set the logging level back to INFO. --- tools/testserver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testserver.py b/tools/testserver.py index 34736ffbf1..d39edb029e 100644 --- a/tools/testserver.py +++ b/tools/testserver.py @@ -53,7 +53,7 @@ except: USE_TORNADO = False -logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG) +logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO) PORT = 34568 LIFESPAN = 180.0 # timeout for the self destruction timer - how much time