Multithreading And Async Execution With Ib_insync
I am facing a perplexing problem when implementing multi-threading with ib_insync. My knowledge of both multithreading and asynchronous programming is surely insufficient to solve
Solution 1:
The function doesn't work fine in either case, it just happens that in the main thread the warning is not shown. RuntimeWarning
on non-awaited coroutines is provided on a best-effort basis without a guarantee that it will be emitted in all circumstances.
To fix the issue, you should avoid mixing threads and asyncio in the first place. For example, if you need to run several coroutines in parallel, you can spawn them as tasks using asyncio.crate_task
, and then await some or all of them. Or you can use the asyncio.gather
utility function which does it for you:
result1, result2, ... = await asyncio.gather(coro1(), coro2(), ...)
Post a Comment for "Multithreading And Async Execution With Ib_insync"