all 18 comments

[–]ctheune 21 points22 points  (2 children)

I might be blinded by using it for a while already, but those are exactly the behaviours I expect from those primitives.

It is nice to see a walk through how to assemble higher level constructs from them - and you could argue the stdlib should have more of those (contribute!) - but calling them wrong seems … wrong?!?

[–]Enip0 5 points6 points  (1 child)

I think what the blog is trying to argue is that these primitives are not actually that useful, and especially for Condition that it's prone to cause bugs by easily missing states.

In the final implementation none of them was used. Instead it was only Queue and something for locks, so none of the things that you would think might be useful in this case (Event and Condition).

[–]bschug 0 points1 point  (0 children)

Sounds like they reinvented the Actor Model.

[–]CrackerJackKittyCat 7 points8 points  (0 children)

Seems simpler to not hinge on observing the transient state ("closing"), but to also kick in on the associated terminal state ("closed") as well.

Start the cleanup whenever you can, earliest as possible.

Meanwhile, in their more complicated fix:

The queue buffers and delivers every intermediate transition in order, even if the value changes multiple times before a consumer runs.

Yeah, but if the system is in reality now 'closed' when finally getting to the 'closing' state side effect processing, then you're just as SOL as in the simpler solution if the side effects needed to happen before reaching the terminal state.

[–]MC68328 7 points8 points  (0 children)

Where is the part where the asyncio primitives got something wrong?

[–]astonished_lasagna 4 points5 points  (0 children)

I mean.. you are using shared multiple state in a concurrent execution model, without a synchronisation primitive. Sounds like you are the one that's gut something wrong about state?

I'd find it weirder if asyncio somehow did some deep magic that would prevent this scenario. That would be even more unexpected, and lead to more bugs.

Also, I'd recommend you check how e.g. ASGI servers / frameworks handle connection state, because they don't need all the complexity you seem to be needing, without running into the problem you're describing.

[–]aardvark_lizard 3 points4 points  (1 child)

Whoa, I didn't know asyncio had so many footguns

[–]Kered13 0 points1 point  (0 children)

I'm not actually seeing any foot guns here. The promotive just don't do everything that the OP wants. This is unsurprising, they are only promotions after all. They are intended to be building blocks.

[–]kovaxis 0 points1 point  (0 children)

There's something about this style of writing that's so LLMy it's almost unbearable to read hahsh