What can go wrong if I do not use an async context manager inside an async function?

Viewed 40

It is possible for me to use use context managers inside asynchronous functions, for example,

async def main():
    with open("Hello.txt", "w") as f:
        f.write("Test123")

asyncio.run(main())

However, I did notice that some people utilize __aenter__ and __aexit__ context managers when dealing with context managers inside asynchronous functions. So far I could not provide an example where not utilizing an asynchronous context manager would result in problems. So my question is simply, how dangerous is it to not be using an asynchronous context manager inside an async function?

0 Answers
Related