Esempio n. 1
0
class ChildProcessForTests(ChildProcess):
    def init(self):
        if test_command == 'child_error_during_init':
            #Pretend we were actually doing something
            FunkyWebServer.parse_args_and_setup_logging()
            logging.info("Child about to fail")
            raise ValueError('I was told to fail')
        elif test_command == 'child_freeze_during_init':
            FunkyWebServer.parse_args_and_setup_logging()
            hold_gil(10 * 60)
        self.server = FunkyWebServer()
        signal.signal(signal.SIGINT, self.signal_handler)

    def signal_handler(self, signum, frame):
        if signum == signal.SIGINT:
            logging.info("Stopping server - process %d", os.getpid())
            self.server.stop()

    def run(self):
        if test_command == 'child_error_during_run':
            raise ValueError('I was told to fail')
        self.server.run()

    def stop(self, timeout=None):
        if hasattr(self, 'server'):
            self.server.stop()
Esempio n. 2
0
class ChildProcessForTests(ChildProcess):

    def init(self):
        if test_command == 'child_error_during_init':
            #Pretend we were actually doing something
            FunkyWebServer.parse_args_and_setup_logging()
            logging.info("Child about to fail")
            raise ValueError('I was told to fail')
        elif test_command == 'child_freeze_during_init':
            FunkyWebServer.parse_args_and_setup_logging()
            hold_gil(10*60)
        self.server = FunkyWebServer()
        signal.signal(signal.SIGINT, self.signal_handler)

    def signal_handler(self, signum, frame):
        if signum == signal.SIGINT:
            logging.info("Stopping server - process %d", os.getpid())
            self.server.stop()

    def run(self):
        if test_command == 'child_error_during_run':
            raise ValueError('I was told to fail')
        self.server.run()

    def stop(self, timeout=None):
        if hasattr(self, 'server'):
            self.server.stop()
Esempio n. 3
0
class ChildProcessForTests(ChildProcess):

    def init(self):
        if test_command == 'child_error_during_init':
            #Pretend we were actually doing something
            FunkyWebServer.parse_args_and_setup_logging()
            logging.info("Child about to fail")
            raise ValueError('I was told to fail')
        elif test_command == 'child_freeze_during_init':
            FunkyWebServer.parse_args_and_setup_logging()
            hold_gil(10*60)
        self.server = FunkyWebServer()

    def run(self):
        if test_command == 'child_error_during_run':
            raise ValueError('I was told to fail')
        self.server.run()

    def stop(self, timeout=None):
        if hasattr(self, 'server'):
            self.server.stop()
Esempio n. 4
0
        return super(ProcessFamilyForTests, self).get_child_process_cmd(child_number) + [
            '--process_number', str(child_number+1)]

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    STARTUP_TIMEOUT = int(get_env("STARTUP_TIMEOUT", "") or "10")
    logging.info("Starting")
    try:
        try:
            server = FunkyWebServer()
            server_thread = None
            family = ProcessFamilyForTests(number_of_child_processes=server.num_children)
            server.family = family
            try:
                try:
                    family.start(timeout=STARTUP_TIMEOUT)
                    server_thread = threading.Thread(target=server.run)
                    server_thread.start()
                    while server_thread.is_alive():
                        server_thread.join(1)
                except KeyboardInterrupt:
                    logging.info("Stopping...")
                    server.stop()
            finally:
                if server_thread and server_thread.is_alive():
                    server_thread.join(5)
        finally:
            stop_threads()
    except Exception as e:
        logging.error("Error in process family test parent process: %s\n%s", e, processfamily._traceback_str())
    logging.info("Done")
Esempio n. 5
0
        return super(ProcessFamilyForTests, self).get_child_process_cmd(child_number) + [
            '--process_number', str(child_number+1)]

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    STARTUP_TIMEOUT = int(os.environ.get("STARTUP_TIMEOUT", "") or "10")
    logging.info("Starting")
    try:
        try:
            server = FunkyWebServer()
            server_thread = None
            family = ProcessFamilyForTests(number_of_child_processes=server.num_children)
            server.family = family
            try:
                try:
                    family.start(timeout=STARTUP_TIMEOUT)
                    server_thread = threading.Thread(target=server.run)
                    server_thread.start()
                    while server_thread.isAlive():
                        server_thread.join(1)
                except KeyboardInterrupt:
                    logging.info("Stopping...")
                    server.stop()
            finally:
                if server_thread and server_thread.isAlive():
                    server_thread.join(5)
        finally:
            stop_threads()
    except Exception as e:
        logging.error("Error in process family test parent process: %s\n%s", e, processfamily._traceback_str())
    logging.info("Done")