News for hackers. Stuff that matters.
Re:Python Threading Beginners Tutorial [video] by MikkoFinell on Thursday August 17, 2017 @07:13AM (#15035634)
Isn't multiprocessing almost syntactically equivalent to--but much more efficient than--threading in python?
Re:Python Threading Beginners Tutorial [video] by wdroz on Thursday August 17, 2017 @07:46AM (#15035821)
The problem is the GIL : https://wiki.python.org/moin/GlobalInterpreterLock

Multiprocessing allows you to use all cores, but you can't share memory like in threads. So you have to Serialize/Deserialize a lot for exchange data.

If your serializations cost are low and need computation power, you should use multiprocessing. If you are just waiting I/O you can use threads.

BTW, modern python "ProcessPoolExecutor" is not designed for compute heavy batch like "Pool" from "multiprocessing".

Re:Python Threading Beginners Tutorial [video] by chrisseaton on Thursday August 17, 2017 @07:28AM (#15035713)
Syntactically equivalent? The syntax is the same - both multiprocessing and threading are achieved through libraries and VM primitives, not by additional syntax.

But if you meant semantically equivalent, no they aren't - threading is shared memory and multiprocessing is message passing. If you were to draw a tree of approaches to concurrency and parallelism, you would probably make this division the root node bisecting the domain into two - it's the two fundamental approaches to doing concurrency.

Re:Python Threading Beginners Tutorial [video] by vitus on Thursday August 17, 2017 @08:03AM (#15035908)
> threading is shared memory and multiprocessing is message passing

In most cases, yes. You can use shared memory buffers for IPC, though, although it typically requires more effort.

Re:Python Threading Beginners Tutorial [video] by pvg on Thursday August 17, 2017 @07:46AM (#15035823)
It's an implementation difference with big practical implications. 'Fundamental divide at the root of all concurrency' seems more than a little overstated.
Re:Python Threading Beginners Tutorial [video] by chrisseaton on Thursday August 17, 2017 @08:02AM (#15035902)
Almost every approach to concurrency fits into either shared memory or message passing.

Those that cross between the two are usually notable for doing that and describe themselves as a hybrid approach.

I think it divides the literature pretty cleanly in two.

Re:Python Threading Beginners Tutorial [video] by alanfranzoni on Thursday August 17, 2017 @10:21AM (#15036997)
Interesting, but mostly pointless IMHO.

Python can't do proper multithreading because of the GIL (excluding Jython and IronPython, of course), hence using threads in Python doesn't benefit anyone.

If you want to learn how to do multithreaded programming, pick a language where multithreading actually works - Java would be a good example. Or just take a look at a POSIX threads tutorial.

If you want to handle concurrency in Python, ignore multithreading. Take a look at the multiprocessing module, or, for a different paradigm, at asyncio or Twisted.

Re:Python Threading Beginners Tutorial [video] by vsajip on Thursday August 17, 2017 @10:29AM (#15037075)
If your threads are doing I/O rather than computation, then the GIL is less of an issue because it will be released until an I/O operation completes. It's only for threads which contend for the CPU that the GIL is a problem.
Re:Python Threading Beginners Tutorial [video] by js2 on Thursday August 17, 2017 @10:28AM (#15037065)
Well this isn't the full story. If you have an I/O bound work-load, say you want to parallelize HTTP requests, threads work just fine.
Re:Python Threading Beginners Tutorial [video] by alanfranzoni on Thursday August 17, 2017 @10:40AM (#15037164)
If you have an I/O bound workload, a reactor or proactor approach are way better. No dealing with locks, race conditions, etc.

I never said it's wrong, it's just pointless. In Python, there's always a better alternative to multithreading which has no shortcomings.

Re:Python Threading Beginners Tutorial [video] by Erwin on Thursday August 17, 2017 @12:30PM (#15038212)
That's assuming all the IO you can block on HAS support for non-threaded concurrency. Things that wrap C libraries may support threads, but not the reactor-of-the-day (twisted? tornado? etc.)
Re:Python Threading Beginners Tutorial [video] by tolgahanuzun on Thursday August 17, 2017 @06:47AM (#15035468)
Nice video series. Why don't you work in a Linux environment?
Re:Python Threading Beginners Tutorial [video] by nickyjaspers on Thursday August 17, 2017 @07:31AM (#15035734)
Should it make a difference then?
Re:Python Threading Beginners Tutorial [video] by tolgahanuzun on Thursday August 17, 2017 @09:57AM (#15036780)
I just wondered. Everyone recommends linux to me. I asked to get the idea. Not a criticism.
Re:Python Threading Beginners Tutorial [video] by agumonkey on Thursday August 17, 2017 @10:45AM (#15037211)
- historically unix/linux is nicer to process data as you want (linux shells + grep / sed / awk .. ), windows only recently got a workable shell.

- most if not all oss languages run on linux

- git used to be way faster for linux (may have changed since)

- programmers tend to enjoy system they can own, less the case on windows unless you work against the system (made for non tech saavy users)