behaviors.py 文件源码

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

项目:rpl-attacks 作者: dhondta 项目源码 文件源码
def kill(self, retries=3, pause=.1):
        try:
            try:
                self.task.get(1)
                self.__set_info('KILLED', "None")
            except (AttributeError, TimeoutError):
                self.__set_info('CANCELLED', "None")
            except UnicodeEncodeError:
                self.__set_info('CRASHED', "None")
            for pid in self.pids:
                try:
                    with open(pid) as f:
                        os.kill(int(f.read().strip()), signal.SIGTERM)
                    os.remove(pid)
                except (IOError, OSError):
                    pass  # simply fail silently when no PID or OS cannot kill it as it is already terminated
            if self.command.__name__.lstrip('_') == 'run' and retries > 0:
                time.sleep(pause)  # wait ... sec that the next call from the command starts
                                   # this is necessary e.g. with cooja command (when Cooja starts a first time for
                                   #  a simulation without a malicious mote then a second time with)
                self.kill(retries - 1, 2 * pause)  # then kill it
        except KeyboardInterrupt:
            self.kill(0, 0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号