News for hackers. Stuff that matters.
Re:Why I’m Learning Perl 6 by supremesaboteur on Wednesday July 26, 2017 @08:33AM (#14855628)
For Python there is no native support for threads because of GIL. You can get around this through multiprocessing etc but these are hacks
Re:Why I’m Learning Perl 6 by anonacct37 on Wednesday July 26, 2017 @02:33PM (#14858862)
You might have chosen bad words, but people reading this should know this statement it false. Python has threads. You can create them and (if you're using linux) see them in the /proc filesystem.

A more accurate statement is: "python bytecode can't execute concurrently w/o something like multiprocessing". The key difference? You can do multithreaded I/O all day long, which is a pretty important use case of threading. You can also hand off work to C and release the GIL, although this isn't as common. Example: XML parsing, regex, numeric work.

FWIW all these gotchas are one of the reasons I love just having complete threading support built in to my language.

Re:Why I’m Learning Perl 6 by chrisseaton on Wednesday July 26, 2017 @02:42PM (#14858948)
> A more accurate statement is: "python bytecode can't execute concurrently

No this isn't any more accurate. Python bytecode does execute concurrently if you have multiple threads. It just doesn't execute in parallel.

Re:Why I’m Learning Perl 6 by ensiferum on Wednesday July 26, 2017 @04:46PM (#14860171)
In fact it is quite common. If you look into the c modules you see a pattern where they release the gil before performing some operation and then reacquire it
Re:Why I’m Learning Perl 6 by askvictor on Wednesday July 26, 2017 @08:45AM (#14855697)
There is native support for threads, it's just that they don't run concurrently.
Re:Why I’m Learning Perl 6 by nothrabannosir on Wednesday July 26, 2017 @09:53AM (#14856171)
At this point the word is so far removed from the meaning in this thread you might as well say a haberdasher supports threads.
Re:Why I’m Learning Perl 6 by askvictor on Wednesday July 26, 2017 @04:53PM (#14860241)
There are valid reasons for programming with threads with only a single CPU (indeed when I learnedb thread programming in the 90s pretty much only single core cpus were available). For instance, IO blocking.
Re:Why I’m Learning Perl 6 by dragonwriter on Wednesday July 26, 2017 @12:46PM (#14857836)
They do run in parallel, so long as all but one are running low-level library code which has released the GIL, but you can't call back into the runtime without grabbing the GIL.
Re:Why I’m Learning Perl 6 by weberc2 on Wednesday July 26, 2017 @10:19AM (#14856345)
While we're being pedantic, they do run concurrently (for example, dispatching a dozen concurrent HTTP requests), they just the GIL prevents most CPU work from executing in parallel.
Re:Why I’m Learning Perl 6 by e12e on Wednesday July 26, 2017 @09:14AM (#14855921)
Afaik erlang has a lock as well - in fact I think most green thread implementations do: what you want/need at a minimum is one os process or thread per cpu core that works as a scheduler and then some form of (co-operative) scheduling with only user-mode/low-overhead context switching?
Re:Why I’m Learning Perl 6 by brightball on Wednesday July 26, 2017 @09:47AM (#14856134)
Scheduling and locking aren't the same thing. Here's a brief excerpt from Joe Armstrong that I found on SO while looking for a good explanation.

> [Erlang] is a concurrent language – by that I mean that threads are part of the programming language, they do not belong to the operating system. That's really what's wrong with programming languages like Java and C++. It's threads aren't in the programming language, threads are something in the operating system – and they inherit all the problems that they have in the operating system. One of the problems is granularity of the memory management system. The memory management in the operating system protects whole pages of memory, so the smallest size that a thread can be is the smallest size of a page. That's actually too big.

> If you add more memory to your machine – you have the same number of bits that protects the memory so the granularity of the page tables goes up – you end up using say 64kB for a process you know running in a few hundred bytes.

With Erlang, there are threads running concurrently across multiple CPU's and a preemptive scheduler within each of those threads. This is all transparent through use of Erlang processes. Essentially, many concurrent schedulers managing hundreds of thousands of processes that start out at 0.5kb each. A JVM thread is 1024kb by comparison and a goroutine is 2kb.

You're getting legitimate concurrency with Erlang, as well as isolation. There are only so many things that a single CPU can do at the same time and that's where the scheduler becomes necessary. The scheduler also ensure that if you fire off 100,000 processes and one of them is CPU intensive that it can't hog the processor and preventing the others allocated to that processor from executing.

Re:Why I’m Learning Perl 6 by yellowapple on Wednesday July 26, 2017 @09:34AM (#14856046)
That doesn't sound right re: Erlang; its everything-is-immutable model is supposed to avoid the need for a GIL. Erlang processes are also preemptive, so there's no possibility for a process to lock up the whole VM (unless it calls into a long-running NIF, but native code is always dangerous in a "crash BEAM if you don't get it right" kind of way).
Re:Why I’m Learning Perl 6 by dragonwriter on Wednesday July 26, 2017 @12:48PM (#14857858)
IIRC, Erlang uses shared mutable state internally, though its not exposed, so it needs to lock around accesses to that, but this isn't equivalent to the Python GIL.
Re:Why I’m Learning Perl 6 by pjmlp on Wednesday July 26, 2017 @08:39AM (#14855661)
Only relevant on CPython, other implementations don't have a GIL.
Re:Why I’m Learning Perl 6 by gebruikersnaam on Wednesday July 26, 2017 @08:47AM (#14855706)
Re:Why I’m Learning Perl 6 by pjmlp on Wednesday July 26, 2017 @09:47AM (#14856127)
Ok, but ZipPy, Jython and IronPython do not.
Re:Why I’m Learning Perl 6 by weberc2 on Wednesday July 26, 2017 @10:23AM (#14856371)
Have Jython and IronPython reached compatibility with Python 3 yet? Last I checked they hadn't, or it was still in alpha.
Re:Why I’m Learning Perl 6 by throwaway7645 on Wednesday July 26, 2017 @01:10PM (#14858069)
Yes, but ain't nobody really using Jython or IronPython. Yes some people are, but I'd bet a very small group of the greater Python whole. You also introduce incompatibilities that way. Perl6 has this in the base implementation, so I don't have to switch to a lesser maintained distribution.
Re:Why I’m Learning Perl 6 by pjmlp on Wednesday July 26, 2017 @10:34AM (#14856483)
I don't know, but Python 3 still isn't relevant to many people.

For example, I have to explicitly install 2.7 to be able to use Cocos2d-x build scripts.

Re:Why I’m Learning Perl 6 by weberc2 on Wednesday July 26, 2017 @11:10AM (#14856814)
Maybe, but it seems like a bad idea to invest in Python 2 (which is teaching is ended of life) just to get parallelism when there are other programming languages that have great concurrency stories and a bright future. That said, if PyPy3 ditches the GIL, let me know!
Re:Why I’m Learning Perl 6 by throwaway7645 on Wednesday July 26, 2017 @01:13PM (#14858103)
Someone posted an article awhile back...people are moving over by a significant amount now.
Re:Why I’m Learning Perl 6 by sli on Wednesday July 26, 2017 @06:02PM (#14860772)
Yeah, "not relevant to many people" is a wildly false claim. If it were anywhere near true, we wouldn't see the level of Python 3 support that we have in the major packages (95.8%).

http://py3readiness.org/

Re:Why I’m Learning Perl 6 by dragonwriter on Wednesday July 26, 2017 @12:57PM (#14857942)
Jython project's latest release and news post was mid-2015; the project would seem to be pining for the fjords, so to speak.

Jython and IronPython are both limited to Python 2.x, ZipPy is WIP without a stable release.

Re:Why I’m Learning Perl 6 by reubano on Thursday July 27, 2017 @02:26AM (#14863074)
But not PyPySTM