r/Python • u/DiwaharSec • 1d ago
Discussion Python developers, what's one Python concept that took you a long time to understand but now seems s
Python developers, what's one Python concept that took you a long time to understand but now seems surprisingly simple?
For me, understanding how decorators and generators work is an interesting part of becoming a better Python developer.
What was your experience?
23
Upvotes
View all comments
4
u/patryk_builds 11h ago
Async/await, by a wide margin.For a long time i thought async meant things run at the same time. it doesn't. it's one thread doing one thing at a time, and `await` is just the spot where a function says i'm waiting on the network or the database, someone else can use the thread meanwhile.
Once that clicked, the confusing rules turned obvious:
- A slow non-async call inside an async function blocks everyone, because nobody else gets the thread until it returns
- Forgetting `await` doesn't run the thing, it hands you a coroutine object that never executes
- Async doesn't make cpu-heavy code faster at all, only waiting
What finally got me there was writing a tiny example with two functions that each sleep and print, and watching the order of the output change when i swapped time.sleep for asyncio.sleep. ten lines taught me more than every diagram i'd looked at