Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> But chances are, you should use none of them.

So, no event-oriented programming in Python, or by some other mechanism, or…?



From the conclusion of the article:

> If you need to get a few URLS fast, a ThreadPoolExecutor is likely the Pareto solution, 99% of the time.

I agree with this. ThreadPoolExecutor is easy to use. In general, using threads in Python to handle concurrent I/O is pretty simple and plenty performant.


It’s a waste if you need coordination between the tasks though. Putting an async task aside and sending only dumb synchronous function calls that never wait is more efficient than blocking a thread while it waits on another.

asyncio with an executor is a good way to run complex tasks in parallel.


I'm not sure whether this was your intention, but I think you are in full agreement with the article.


Or just use an async Http client with a little asyncio snippet. Depends on what you're comfortable with and what code you have running already.

If you're a junior and have no clue, your best bet is to ask a senior in your team though.


> So, no event-oriented programming in Python, or by some other mechanism, or…?

My guess he's saying that anything that introduces concurrency is hard, and best avoided if you can do so. He's not wrong. True event driven code (without these libraries) introduces a lot of unneeded concurrency. You see it at it's worst in older UI's. There a central event loop receives mouse, keyboard and io events from the OS. The event handlers it calls transforms those events into higher level events like "field changed" and "focus change", and re-injects them into the event loop, where they get turned into still higher level events like "modal dialogue closed" until the job is done. It's a prick of a way to write a program.

If you just want parallelism (as he defines it in the article), threads with their conventional stack model are far easier to use. The problem with conventional threads is that you also get unwanted concurrency and the heisenbugs that go along with that. But green threads (aka fibres, aka cooperative multitasking) eliminate that sort of non-determinism. Green threads are what effectively gevent provides. That's why he's so positive about it.

The other libraries he discusses aren't about event oriented programming either. Rather, they tame the event loop, allowing you to write code in a way that looks similar to threaded code. And they do it without introducing unwanted non-determinism. But they come at the cost of coloured methods, so you have 2 ways of doing everything. That is why asyncio has no ftp / smtp libraries - because they have to be written in the different colour. With green threads (and gevent) all that old code continues to work. That is why these libraries suck compared to green threads. But if you have a language like javascript that doesn't have threads, they are a huge leap forward over the raw event loop processing so you'd take it any day.

What has me scratching my head is why Python introduced these higher level event libraries at all. They own the language - they could have gone the green thread route. As for Rust introducing colored code - words fail me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: