I am creating a subprocess from my FastAPI application as follows:
proc = await asyncio.create_subprocess_shell(
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
I am using the asyncio.create_subprocess_shell
module function for the purpose of capturing the program's stdout line by line.
How can I make it so that the process uses a specific executor? I tried this:
pool = ProcessPoolExecutor(max_workers=10)
loop = asyncio.get_running_loop()
task = partial(
asyncio.create_subprocess_shell,
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
proc = await loop.run_in_executor(pool, task)
But it fails with this error:
TypeError: cannot pickle 'coroutine' object