Closed ghost closed 3 years ago
You're not doing anything wrong. What aiofiles does is delegate the file reading operations to a threadpool. This approach is going to be slower than just reading the file directly. The benefit is that while the file is being read in a different thread, your application can do something else in the main thread.
A true, cross-platform way of reading files asynchronously is not available yet, I'm afraid :)
hi developers I have a question I'm new to the python async world and I write some code to test the power of
asyncio
, I create 10 files with random content, namedfile1.txt, file2.txt, ..., file10.txt
here is my code:
and got this result:
why Asynchronous code take longer than Synchronous code ? where I do it wrong ?