首页 > 解决方案 > 获取 OSError:[WinError 6] 句柄无效

问题描述

我用多处理实现运行我的函数

def assign_task(self, module, command):
        logging.debug("Assigning task for {0}".format(command._get_module_id()))
        if self.queue is None:
            self.queue = JoinableQueue()
        if self.processes is None:
            self.processes = [Process(target=self.do_execute) for i in range(self.max_process)]
            for process in self.processes:
                process.daemon = True
                process.start()

        logging.debug("Queuing message {0}".format(command._get_module_id()))
        self.queue.put((module, command))

    def do_execute(self):
        # the code

但收到此错误

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\muhammad.aqshol\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 107, in spawn_main
    new_handle = reduction.duplicate(pipe_handle,
  File "C:\Users\muhammad.aqshol\AppData\Local\Programs\Python\Python38\lib\multiprocessing\reduction.py", line 79, in duplicate
    return _winapi.DuplicateHandle(
OSError: [WinError 6] The handle is invalid

我在实施上错了还是缺少了什么?

标签: pythonmultiprocessing

解决方案


推荐阅读