Skip to content
Advertisement

Write a CSV file asynchronously in Python

I am writing a CSV file with the following function:

JavaScript

However, as there is no await allowed over writerows method, there are no rows being written into the CSV file.
How to resolve this issue? Is there any workaround available?
Thank you.
Entire code can be found here.

Advertisement

Answer

In my opinion it’s better not to try to use the aiofiles with the csv module and run the synchronous code using loop.run_in_executor and wait it asynchronously like below:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement