Esempio n. 1
0
    def _sys_in_thread_target(self):
        should_continue = True
        while should_continue:
            try:
                line = self.stdin.readline()
                if not line:
                    should_continue = False
                else:
                    try:
                        should_continue = self._handle_command_line(line)
                    except Exception as e:
                        logger.error("Error handling processfamily command on input: %s\n%s", e,  _traceback_str())
            except Exception as e:
                logger.error("Exception reading input for processfamily: %s\n%s", e,  _traceback_str())
                # This is a bit ugly, but I'm not sure what kind of error could cause this exception to occur,
                # so it might get in to a tight loop which I want to avoid
                time.sleep(5)

        self._should_stop = True
        self._started_event.wait(1)
        threading.Thread(target=self._stop_thread_target).start()
        self._stopped_event.wait(3)
        #Give her ten seconds to stop
        #This will not actually stop the process from terminating as this is a daemon thread
        time.sleep(10)
        #Now try and force things
        stop_threads()
Esempio n. 2
0
    def _sys_in_thread_target(self):
        should_continue = True
        while should_continue:
            try:
                line = self.stdin.readline()
                if not line:
                    should_continue = False
                else:
                    try:
                        should_continue = self._handle_command_line(line)
                    except Exception as e:
                        logger.error(
                            "Error handling processfamily command on input: %s\n%s",
                            e, _traceback_str())
            except Exception as e:
                logger.error(
                    "Exception reading input for processfamily: %s\n%s", e,
                    _traceback_str())
                # This is a bit ugly, but I'm not sure what kind of error could cause this exception to occur,
                # so it might get in to a tight loop which I want to avoid
                time.sleep(5)

        self._should_stop = True
        self._started_event.wait(1)
        stop_thread = threading.Thread(target=self._stop_thread_target,
                                       name="pf_%s_stop" %
                                       repr(self.child_process))
        stop_thread.daemon = True
        stop_thread.start()
        self._stopped_event.wait(3)
        #Give her ten seconds to stop
        #This will not actually stop the process from terminating as this is a daemon thread
        time.sleep(10)
        #Now try and force things
        stop_threads()
Esempio n. 3
0
 def SvcDoRun(self):
     servicemanager.LogInfoMsg("ProcessFamilyTest starting up ..." )
     try:
         logging.getLogger().setLevel(logging.INFO)
         self.server = FunkyWebServer()
         logging.info("Starting process family")
         family = ProcessFamilyForWin32ServiceTests(number_of_child_processes=self.server.num_children)
         self.server.family = family
         family.start(timeout=10)
         servicemanager.LogInfoMsg("ProcessFamilyTest started")
         try:
             logging.info("Starting HTTP server")
             self.server.run()
         except KeyboardInterrupt:
             logging.info("Stopping...")
     except Exception as e:
         logging.error("Error in windows service: %s\n%s", e, _traceback_str())
     finally:
         logging.info("Stopping")
         stop_threads(exclude_thread_fn=lambda t: t.getName() != 'MainThread')
     servicemanager.LogInfoMsg("ProcessFamilyTest stopped" )
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")