This paste expires on 2023-07-26 14:30:54.261039. Repaste, or download this paste. . Pasted through web.

import asyncio
import concurrent
def cpu_bound(job_def):
    pass
fifo_queue = asyncio.Queue()
async def fifo_worker_task():
    loop = asyncio.get_running_loop()
    with concurrent.futures.ProcessPoolExecutor() as pool:
        while True:
            job_def = await fifo_queue.get()
            #Option 1, this will block
            result = await loop.run_in_executor(pool, cpu_bound, job_def)
            # Option 2, schedule and continue
            future = pool.submit(cpu_bound, job_def)
Filename: None. Size: 529b. View raw, , hex, or download this file.