ASYNC file I/O in Python
HTML-код
- Опубликовано: 29 авг 2024
- Need to read and write files in your async application? Aiofiles is exactly what you’re looking for.
-
If you enjoy my content, consider supporting me on Patreon or becoming a member!
patreon.carber...
join.carberra.xyz
If you need help with anything, feel free to join the Discord server:
discord.carber...
I get a lot of people asking, so here's my Visual Studio Code setup!
• My Visual Studio Code ...
-
If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so.
#python #coding #shorts
I love the auto-generated captions!
"aero-files"
"AOL-files"
Just a dumb question. But what are the benefits? Am I understanding this right that when I write to this file a few GB data the program continues it's run and will not hang until the data is written? And what if I need to write into the file from another function but the file is still written to?
1) Pretty much right. It's basically so you don't block async applications. 2) You'd need to handle that yourself.
@@Carberra What? Doesn't the await keyword make it wait anyway, so the program *doesn't* continue execution? Or did I misunderstand async. Isn't this only beneficial if we read/write many files at once, and then await them all at the same time?
You've misunderstood, though the terminology is a bit odd with the whole "await" thing. I did a video a little while that better explains async (ruclips.net/video/vLbZUVKFVxY/видео.html). Aiofiles specifically is probably most beneficial in something like a bot, or some other service that's running 24/7.
Btw what is the best way to use postgres asynchronously?
Asyncpg is your best bet I believe.