jobmonitor.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:LMS 作者: RRZE-HPC 项目源码 文件源码
def recv_loop(self, configfile=None):
        """
        This is the main loop receiving data and calling functions. First it calls
        the read_config function if not done previously. Afterwards it connects the
        ZeroMQ publisher.
        The reception is non-blocking. If nothing is received, the JobMonitor sleeps
        for a second. This is no problem since ZeroMQ queues the strings.
        Each loop checks whether it is time to call the update function.
        If the filter applies, it is analyzed for the status attribute and if it exists,
        the value is checked whether a function is registered for it and finally calls it.
        """
        if not self.config:
            self.read_config(configfile=configfile)
        if not self.context:
            self.connect()

        updatetime = datetime.datetime.now() + datetime.timedelta(seconds=self.interval)
        while not self.terminate:
            s = None
            try:
                s = self.socket.recv(flags=zmq.NOBLOCK)
            except zmq.Again as e:
                time.sleep(1)
            except KeyboardInterrupt:
                self.terminate = True
                pass
            if not self.terminate:
                if datetime.datetime.now() > updatetime:
                    logging.debug("Calling update function")
                    self.update()
                    updatetime = datetime.datetime.now() + datetime.timedelta(seconds=self.interval)
                if s and self._filter(s):
                    logging.debug("Received string: %s" % s)
                    m = Measurement(s)
                    if self.status_attr:
                        logging.debug("Checking status_attr: %s" % self.status_attr)
                        stat = m.get_attr(self.status_attr)
                        if stat:
                            for key in self.stat_funcs:
                                if key == stat:
                                    logging.debug("Calling %s function" % key)
                                    self.stat_funcs[key](m)
                    self.get(m)
        self.disconnect()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号