yandextank/plugins/Bfg/worker.py
def _worker(self):
        """
        A worker that does actual jobs
        """
        logger.debug("Init shooter process")
        try:
            self.gun.setup()
        except Exception:
            logger.exception("Couldn't initialize gun. Exit shooter process")
            return
        while not self.quit.is_set():
            try:
                task = self.task_queue.get(timeout=1)
                if not task:
                    logger.debug("Got killer task.")
                    break
                timestamp, missile, marker = task
                planned_time = self.start_time + (timestamp / 1000.0)
                delay = planned_time - time.time()
                if delay > 0:
                    time.sleep(delay)

                try:
                    with self.instance_counter.get_lock():
                        self.instance_counter.value += 1
                    self.gun.shoot(missile, marker)
                finally:
                    with self.instance_counter.get_lock():
                        self.instance_counter.value -= 1

            except (KeyboardInterrupt, SystemExit):
                break
            except Empty:
                if self.quit.is_set():
                    logger.debug("Empty queue. Exiting process")
                    return
            except Full:
                logger.warning("Couldn't put to result queue because it's full")
            except Exception:
                logger.exception("Bfg shoot exception")

        try:
            self.gun.teardown()
        except Exception:
            logger.exception("Couldn't finalize gun. Exit shooter process")
            return
        logger.debug("Exit shooter process")
def _worker(self):
        """
        A worker that does actual jobs
        """
        logger.debug("Init shooter process")
        try:
            self.gun.setup()
        except Exception:
            logger.exception("Couldn't initialize gun. Exit shooter process")
            return
        while not self.quit.is_set():
            try:
                task = self.task_queue.get(timeout=1)
                if not task:
                    logger.debug("Got killer task.")
                    break
                timestamp, missile, marker = task
                planned_time = self.start_time + (timestamp / 1000.0)
                delay = planned_time - time.time()
                if delay > 0:
                    time.sleep(delay)

                try:
                    with self.instance_counter.get_lock():
                        self.instance_counter.value += 1
                    self.gun.shoot(missile, marker)
                finally:
                    with self.instance_counter.get_lock():
                        self.instance_counter.value -= 1

            except (KeyboardInterrupt, SystemExit):
                break
            except Empty:
                if self.quit.is_set():
                    logger.debug("Empty queue. Exiting process")
                    return
            except Full:
                logger.warning("Couldn't put to result queue because it's full")
            except Exception:
                logger.exception("Bfg shoot exception")

        try:
            self.gun.teardown()
        except Exception:
            logger.exception("Couldn't finalize gun. Exit shooter process")
            return
        logger.debug("Exit shooter process")
def _worker ( self ) : logger . debug ( "Init shooter process" ) try : self . gun . setup ( ) except Exception : logger . exception ( "Couldn't initialize gun. Exit shooter process" ) return while not self . quit . is_set ( ) : try : task = self . task_queue . get ( timeout = 1 ) if not task : logger . debug ( "Got killer task." ) break timestamp , missile , marker = task planned_time = self . start_time + ( timestamp / 1000.0 ) delay = planned_time - time . time ( ) if delay > 0 : time . sleep ( delay ) try : with self . instance_counter . get_lock ( ) : self . instance_counter . value += 1 self . gun . shoot ( missile , marker ) finally : with self . instance_counter . get_lock ( ) : self . instance_counter . value -= 1 except ( KeyboardInterrupt , SystemExit ) : break except Empty : if self . quit . is_set ( ) : logger . debug ( "Empty queue. Exiting process" ) return except Full : logger . warning ( "Couldn't put to result queue because it's full" ) except Exception : logger . exception ( "Bfg shoot exception" ) try : self . gun . teardown ( ) except Exception : logger . exception ( "Couldn't finalize gun. Exit shooter process" ) return logger . debug ( "Exit shooter process" )
A worker that does actual jobs
A worker that does actual jobs