Concurrent.futures code ends up with “BrokenProcessPool”

点点圈 提交于 2021-01-28 02:22:14

问题


Yesterday I asked a similar question and somebody suggested me to use concurrent.futures and asyncio. What I want is skipping the file if it takes too long to process. Here is my code:

import os, glob
import time
import asyncio
from concurrent.futures import ProcessPoolExecutor
@asyncio.coroutine
def coro(loop, of, filename):
    ex = ProcessPoolExecutor(4)
    yield from loop.run_in_executor(ex, os.system, "\"C:\\P.exe\" -o {} {}".format(of, filename))

for folder, subfolders, filenames in os.walk(directory):
         if any([filename.endswith('.scad') for filename in filenames]):
             if filename.endswith('.scad'):
                 os.chdir(folder)
                 of = filename.replace('.scad', '.stl') # name of the outfile .stl
                 try:
                    loop.run_until_complete(asyncio.wait_for(coro(loop, of, filename), 90))
                 except asyncio.TimeoutError:
                    print("Timed out file: {}".format(filename))
                    pass

And the error that I get is:

raise self._exception
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

Any ideas ?

来源:https://stackoverflow.com/questions/44923476/concurrent-futures-code-ends-up-with-brokenprocesspool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!