diff --git a/tools/ResponseProvider.py b/tools/ResponseProvider.py index 5b8bb25143..a7fb3b95c3 100644 --- a/tools/ResponseProvider.py +++ b/tools/ResponseProvider.py @@ -1,5 +1,7 @@ from __future__ import print_function +import logging + BIG_FILE_SIZE = 47684 @@ -193,5 +195,6 @@ class ResponseProvider: def kill(self): + logging.debug("Kill called in ResponseProvider") self.delegate.kill() return Payload("Bye...") diff --git a/tools/SiblingKiller.py b/tools/SiblingKiller.py index 031d299b5a..5ffe5a269c 100644 --- a/tools/SiblingKiller.py +++ b/tools/SiblingKiller.py @@ -1,10 +1,13 @@ from __future__ import print_function -import re +import logging + import os +import re import urllib2 import socket from subprocess import Popen, PIPE +from time import sleep import logging @@ -22,7 +25,10 @@ class SiblingKiller: def allow_serving(self): return self.__allow_serving + def give_process_time_to_kill_port_user(self): + sleep(5) + def kill_siblings(self): """ The idea is to get the list of all processes by the current user, check which one of them is using the port. @@ -33,15 +39,13 @@ 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. """ - self.kill_process_on_port() # changes __allow_serving to True if the process was alive and serving - sibs = self.siblings() - if self.__allow_serving: - self.kill(pids=sibs) - return - for sibling in sibs: + logging.debug("Checking whether we should kill sibling id: {}".format(sibling)) + + self.give_process_time_to_kill_port_user() + if self.wait_for_server(): serving_pid = self.serving_process_id() if serving_pid: @@ -50,6 +54,9 @@ class SiblingKiller: return else: self.kill(pid=sibling) + + self.kill_process_on_port() # changes __allow_serving to True if the process was alive and serving + def kill(self, pid=0, pids=list()): diff --git a/tools/testserver.py b/tools/testserver.py index 0fa53ea61b..d39edb029e 100644 --- a/tools/testserver.py +++ b/tools/testserver.py @@ -53,31 +53,7 @@ except: USE_TORNADO = False -dict = { - 'version': 1, - "handlers": { - "console": { - "class" : "logging.StreamHandler", - "formatter": "default", - "level" : "DEBUG", -# "stream" : "ext://sys.stdout" - } - }, - - "formatters": { - "default":{ - "format": '%(asctime)s %(levelname)-8s %(name)-15s %(message)s', - "datefmt": '%Y-%m-%d %H:%M:%S' - } - } - } - - -# logging.config.dictConfig(dict) - - -logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG) -logging.warning('is when this event was logged.') +logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO) PORT = 34568 LIFESPAN = 180.0 # timeout for the self destruction timer - how much time @@ -228,6 +204,7 @@ class PostHandler(BaseHTTPRequestHandler, ResponseProviderMixin): def kill(self): + logging.debug("Kill called in testserver") self.server.suicide() diff --git a/tools/tornado_handler.py b/tools/tornado_handler.py index 88f4be2bdf..017bf4fc6a 100644 --- a/tools/tornado_handler.py +++ b/tools/tornado_handler.py @@ -71,8 +71,10 @@ class MainHandler(tornado.web.RequestHandler, ResponseProviderMixin): @staticmethod def reset_self_destruct_timer(): if MainHandler.self_destruct_timer: + logging.debug("Canceling the kill timer") MainHandler.self_destruct_timer.cancel() - MainHandler.self_destruct_timer = Timer(MainHandler.lifespan, MainHandler.suicide()) + MainHandler.self_destruct_timer = Timer(MainHandler.lifespan, MainHandler.suicide) + logging.debug("Starting the kill timer") MainHandler.self_destruct_timer.start()