Hacker News new | past | comments | ask | show | jobs | submit login

It's not unfair to say that python doesn't do multithreading either.



It supports it as a language construct, even though the GIL gets in the way of actual parallelism. As far as I'm aware, EMCAScript doesn't provide any concept of threading within the language itself. You can get it by spinning up multiple separate VMs in separate threads and passing messages back and forth (which is what web workers are), but that's a function of how the VM is presented in the context of a larger application, not a feature of the language itself. Jython and JRuby don't have GILs and are able to achieve full parallelism using the same language constructs that CPython and MRI use.


I don't think you can even achieve that kind of concurrency (multiple seperate VMs in seperate threads running in parallel) with Python, though. As I understand it the GIL really is global - it's shared across every single VM in every thread within the current process, at least in the CPython 2.x series, and that's not easy to fix because it's protecting global shared state.


If they're running separate VMs then your threads aren't really threaded in any meaningful sense; you could equally well run those VMs in separate processes (shared-memory communication between distinct processes is not completely trivial but it's very much doable).


Last I looked, you are correct, but Python isn't designed as an embeddable language, either. Multiple VMs usually isn't something you'd have any desire to do specifically because you can achieve multithreading from within the language itself.

If you need multiple, separate VMs (ie, to drive multiple isolated scripting engines in a game), then v8 isolates or Lua contexts will do you just fine, but that's a different use case than most places where you'd want to use concurrent Python.


Python totally is designed as an embeddable language; that's why there's a giant section called "Embedding Python in Another Application" in the reference manual:

https://docs.python.org/2/extending/embedding.html

It's just that at the time Python was created, multithreading was not something you generally did in a C program. The POSIX thread standard didn't come out until 1996. Python was started in 1989, first released in 1991, and reached 1.0 in 1994. Common rules of thumb for dealing with multithreaded programs (eg. "Avoid global or static data") didn't really become popularized until the 2000s, and many programmers in less well-informed circles still don't know them.


What I mean is that while Python's embeddable, it wasn't designed specifically as an embeddable language in the same way that Javascript or Lua were.


Ok, ok. I won't make anymore jokes about the GIL.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: