python multriprocess在close()中挂起

2024-05-19 20:27:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行一个python代码作为linux守护进程。它必须产生几个连接到串行、网络摄像头和其他资源的子进程。我用这种方式运行它们:


def start_modules(self, modules, warn=False):
    for module in modules:
        if not self.modules[module].is_alive():
            self.modules[module].start()
        elif warn:
            logger.warning("Already live module %s", module)

我试着尽可能温柔干净地关上它们。这是我在停止守护进程之前需要清理的函数。执行显然在.close()调用中挂起

    def shutdown_modules(self, modules, closing_time, termination_time, killing_time):
       logger.info("Gentle closing")
            for module_name in modules:
                module = self.modules[module_name]
                start_mark = time.time()
                grace_time = max(closing_time, 1)
                if module.is_alive():
                    logger.info("Awaiting %s to %s ", grace_time, module_name)
                    module.join(grace_time)
                    logger.info("awaited %s for %s", start_mark - time.time(), module_name)
                else:
                    logger.info("%s: try gently closing", module.name)
                    module.close()
                    logger.info("%s: gently closed", module.name)
                    modules.pop(module_name)
                closing_time -= time.time() - start_mark

该功能是较长的,使其他任务,但他们从来没有达到,所以我削减,然后为清楚

我从正常的进程执行中调用了这段代码,并形成了一个信号处理程序,但结果是一样的


Tags: 代码nameselfinfomodulesfortime进程