Relative Content

Tag Archive for pythonpython-asyncio

How to call asyncio.create_task() within asyncio.create_task()?

I have been attempting to run 10 different looping tasks simultaneously with asyncio. All 10 tasks call “asyncio.create_task()” within their loops. I can’t use “asyncio.run()” on all of them because this functions blocks the thread its called on until the task is done. So I thought that I could simply circumvent this by calling a function with “asyncio.run()” and then inside that function call my 10 looping functions through “asyncio.create_task()”. The 10 looping functions are indeed called, but they themselves cannot use “asyncio.create_task()”. Any suggestions on how to fix this issue?

Using asncio or multiprocessing in python correctly

I need to convert a bunch of .xlsx files to pdf files. I use Linux mint and I wrote script that do the job correctly if processing is done sequentially. However this takes a lot of time and I would like to speed up the things by running concurrently. The idea is to split a list of files needed to be converted in half and do these concurrently and independently. This should work since files are independent from each other.
I tried to use asyncio for this purpose and asked ChatGPT for help, but I cannot solve the problem, because randomly about 10 files (number varies) out of 100
just fail to convert to pdf.
I need y our help to understand what is going on.
The original script used the following approach and it works slow, but correct: