Closed smarlowucf closed 6 years ago
This is more a question than an issue but I was curious if there's a better way with Curio to spawn multiple blocking functions?
For example:
import curio def fib(n): if n < 2: return 1 fib = 1 prev = 1 for i in range(2, n): prev, fib = fib, fib + prev async def async_fib(i): await curio.run_in_process(fib, i) async def main(): tasks = [] for i in range(10000, 11000): task = await curio.spawn(async_fib, i) tasks.append(task) for task in tasks: await task.join() curio.run(main)
Had to use the extra async_fib coroutine to make it run concurrently.
async_fib
Can you not do curio.spawn(curio.run_in_process, fib, i)?
curio.spawn(curio.run_in_process, fib, i)
Yes, calling curio.spawn on curio.run_in_process ought to do the trick.
curio.spawn
curio.run_in_process
Aha, yep. That does it. Thanks!
This is more a question than an issue but I was curious if there's a better way with Curio to spawn multiple blocking functions?
For example:
Had to use the extra
async_fib
coroutine to make it run concurrently.