detector.py 文件源码

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

项目:amadash 作者: ipartola 项目源码 文件源码
def handle_button_traffic(self, mac, eth_protocol):
        button = self.buttons.get(mac)
        if not button:
            return

        now = time.time()
        time_delta = now - button['last_seen']
        button['last_seen'] = now
        if time_delta < options.main.button_timeout:
            return

        logging.getLogger().info('Button press detected: {} [{}].'.format(button['name'], button['mac']))
        action = button['action']
        env = dict(os.environ)
        env.update({
            'BUTTON_NAME': button['name'],
            'BUTTON_MAC': button['mac'],
        })

        pid = None
        try:
            pid = os.fork()
        except OSError as e:
            logging.getLogger().info("Could not fork for action: [{}] {}".format(e.errno, e.strerr))

        if pid == 0:
            daemonize(False)
            subprocess.Popen(action, shell=True, env=env).wait()
            os._exit(0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号