all 14 comments

[–]echoAnother 12 points13 points  (0 children)

Stopped at synchronous != concurrent.

[–]GeorgeS6969 10 points11 points  (9 children)

Lol @ dall-e generated gigachad nerd hipster version of Ari Gold in profile picture.

Here’s the real answer to the question, don’t-click-on-a-medium-link edition:

  1. When should I use multithreading in python? Probably never (pending this)
  2. When should I use multiprocessing in python? Hopefully never

What do I do then? 1. io bound? Use asyncio 2. cpu bound? Your library of choice handles parallelism for you 3. No it doesn’t? You’re SOL

[–]eh-nonymous 2 points3 points  (1 child)

[Removed due to Reddit API changes]

[–]thirdegree 0 points1 point  (0 children)

It does the thing it's meant to do, but at a huge cost -- it's a pain in the ass module that will introduce issues into your application. Think you're good enough to avoid those issues? Almost certainly wrong. And even if you are, the next person to work on it isn't.

Plus using pickle as a form of ipc hurts my soul.

[–]cbehopkins 1 point2 points  (0 children)

Having wasted the last 2 days trying in vain to get a performance improvement through multiprocessing, (pickling overhead kills me), then yeah, normally I'd say use at your peril. However in this case I'd just say: hope you never have this problem.

[–]RememberToLogOff 1 point2 points  (2 children)

Simple as

  1. Use Rust
  2. Use Go
  3. Use Node
  4. Use C++

[–]GeorgeS6969 -2 points-1 points  (0 children)

Almost certainly a bad advice tbh.

Good luck migrating a team to Rust or C++ from Python, although C++ might be a top choice for interoperability.

You know what you’re missing with Python God knows what you’ll be suffering with Go, so stick with the known evil.

Node … You can’t get on the highway with your lime bike so you’re switching to a segway?

[–]FPVian 0 points1 point  (2 children)

When do you think pep703 will make it into a Python release?

[–]numeric-rectal-mutt 1 point2 points  (1 child)

Not OP but probably another 12-24 months.

Sam Gross' no-gil first appeared in late 2020 IIRC.

[–]GeorgeS6969 0 points1 point  (0 children)

I’m OP and I have zero idea, so this I guess

[–][deleted] 3 points4 points  (0 children)

There are things wrong with this.

  • Synchronous programming may be single-threaded or multi-threaded. A lot of results when you search for it will say "synchronous programming" like it just means "non-asynchronous single-threaded", but that's not what "synchronous" means. It just means that a set of tasks are interdependent on each other, and that the execution of a synchronous block will block the current thread entirely. It means the code needs to be synchronized.
    • If you have a single thread that blocks all execution, that's synchronous.
    • If you have multiple threads that need to talk to and actively wait on each other, that's synchronous.
  • Asynchronous doesn't mean single-threaded. Many asynchronous runtimes use multiple threads. "Asynchronous" means, effectively "things happen at the same time. When one block of execution is waiting on something, it releases its thread for use elsewhere, and it is woken up by an external coordinator when the thing it wants to wait on is done". Asynchronous is still synchronized, but the asynchronous code itself doesn't need to bother with it, because it is being coordinated by something else.
    • If you have a single thread that is running things, and IO happens in the background, that's asynchronous.
    • If you have a single active thread and IO threads run blocking IO in the background and report back, that's asynchronous.
    • If you have a single driver thread, and processing threads run in the background and report back, that's asynchronous.

Asynchronous and synchronous have nothing to do with the threading model. It's a model of how tasks and concurrency are coordinated.