import asyncio from functools import partial from subprocess import run semaphore = asyncio.Semaphore(2) async def process_pdf(file_path, ctx): async with semaphore: # Set status to runnin cmd = "cmd" process = await asyncio.create_subprocess_exec(cmd) await process.await() # Set status to done.