top | item 32003104

(no title)

hn_saver | 3 years ago

Threading IS concurrency. When you say "real" concurrency, you actually mean parallelism.

discuss

order

bornfreddy|3 years ago

Not in CPython it isn't. Threading in CPython doesn't allow 2 threads to run concurrently (because of GIL). As GP correctly stated, you need multiprocessing (in CPython) for concurrency.

bulatb|3 years ago

They're emphasizing a precise distinction between "concurrent" (the way it's structured) and "parallel" (the way it runs).

Concurrent programs have multiple right answers for "Which line of computation can make progress?" Sequential execution picks one step from one of them and runs it, then another, and so on, until everything is done. Whichever step is chosen from whichever computation, it's one step per moment in time; concurrency is only the ability to choose. Parallel execution of concurrent code picks steps from two or more computations and runs them at once.

Because of the GIL, Python on CPython has concurrency but limited parallelism.

dragonwriter|3 years ago

> Threading in CPython doesn't allow 2 threads to run concurrently (because of GIL)

It does allow threads to execute concurrently. It doesn't allow them to execute in parallel if they all are running Python code (if at least one is rubbing native code and has released the GIL, then those plus one that has not can run in parallel.)