Multiprocessing in FastAPI

Reason is the light and the light of life.

Jerry Su Jul 28, 2022 1 mins"/async-endpoint")
async def test_endpoint():
        loop = asyncio.get_running_loop()
        with concurrent.futures.ProcessPoolExecutor(max_workers=1) as pool:
            results = await loop.run_in_executor(pool,
                                                  *(args, subject_check_rules, docx_paras, pdf_paras))  # wait result
    except Exception as err:
        logger.error(f"Subprocess execute fail: {str(err)}")
        results = []
    return results

Read more:

Related posts: