Running asyncio.run() more than once
Clint Olsen
clint.olsen at gmail.com
Tue Mar 14 03:08:50 EDT 2023
On Monday, March 13, 2023 at 11:55:22 PM UTC-7, gst wrote:
> Le mardi 14 mars 2023 à 02:32:23 UTC-4, Clint Olsen a écrit :
> I'm not asyncio expert or even not advanced user, but using a simple list to hold the jobs to execute and fill it as necessary after results gathering is not good ?
>
> ```
> @async
> def execute_jobs(jobs: List["Job"]):
> while len(jobs) > 0:
> # launch_job(s)
> # gather_job(s)_result(s)
> # append_jobs_if_desired
> ```
The problem with this implementation is that most/all of the code calling this app is not async code. So, we'd need a method (and thread) to communicate between the sync and async worlds.
A possible implementation is here: https://stackoverflow.com/questions/59650243/communication-between-async-tasks-and-synchronous-threads-in-python
So, while this is certainly possible, it would be much more straightforward to just call asyncio.run() more than once.
Thanks,
-Clint
More information about the Python-list
mailing list