| 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)
|