News for hackers. Stuff that matters.
Re:Solving multi-core Python by JoshTriplett on Thursday July 09, 2015 @10:57PM (#9862062)
Interpreter state isn't the only problem; if that were the only issue, it'd be a more tractable problem.

However, built on top of CPython's C API are a huge pile of libraries that assume they can manipulate global or per-data-structure state without locking.

Re:Solving multi-core Python by viraptor on Thursday July 09, 2015 @11:03PM (#9862075)
While technically correct, it's not as bad as explained here. They don't assume they can manipulate global state. They are guaranteed that it's right because native calls happen with GIL in place. That's an existing and real contract. If you don't want the lock in your library, you can release it. But your native code will always start in GIL-locked state.
Re:Solving multi-core Python by zabbadabba on Thursday July 09, 2015 @11:14PM (#9862106)
Avoiding fixing the C API for the sake of backwards compatibility is the reason for the GIL mess. Python 3 had a chance to correct the API situation since they were starting anew, but it didn't happen. All these API half measures are just dancing around the real problem of not having truly independent interpreter instances.
Re:Solving multi-core Python by pekk on Friday July 10, 2015 @12:44AM (#9862338)
Python 3 wasn't really starting anew, they were also balancing the ongoing screaming about every difference from Python 2.
Re:Solving multi-core Python by zabbadabba on Friday July 10, 2015 @10:14AM (#9864043)
It is curious how they completely revamped Python making most Python3 code incompatible with Python2 and yet they wanted to preserve C API "compatibility". Compatibility with what? Most Python3 modules had to be rewritten anyway - it was the perfect opportunity to fix the C API and get rid of the GIL once and for all.
Re:Solving multi-core Python by ericsnow on Friday July 10, 2015 @12:21PM (#9864869)
you forgot your <hand-wavy gross exaggeration> tags
Re:Solving multi-core Python by frozenport on Friday July 10, 2015 @12:07AM (#9862254)
I don't understand. Can you give an example of a library that has a global resource that isn't thread safe?

Also how is this different then problems faced when using multiprocessing style parallelism with the same library?

Re:Solving multi-core Python by JoshTriplett on Friday July 10, 2015 @02:04AM (#9862506)
A few random examples, all from in-tree Python modules that are completely typical examples of what you'd find out-of-tree as well:

The readline module uses libreadline, which maintains internal global state on the C side.

The standard library has lists and dictionaries, which are not thread-safe to access from two threads simultaneously, and are not in any way locked.

Re:Solving multi-core Python by exDM69 on Friday July 10, 2015 @05:02AM (#9862939)
> The standard library has lists and dictionaries, which are not thread-safe to access from two threads simultaneously, and are not in any way locked.

Locking lists and dicts, etc would not be a reasonable thing to do. There must be some granularity in synchronization, it's clearly not a good idea to attempt to allow mutating any object from multiple threads without explicit locking.

Things like readline are issues that programmers have to deal with when writing multi threaded code in any language. There are libs which are not thread safe or which have global state or need special handling with threads (e.g. OpenGL). That's no reason to disallow threading completely.

However, this might be a big culture shock issue if Python were to suddenly start supporting proper concurrency without GIL. None of the libraries document whether they are thread safe or not, so there would be surprises ahead.

Re:Solving multi-core Python by Erwin on Friday July 10, 2015 @05:32AM (#9863007)
Locking the basic data structures seems like it would destroy Python's simplicity. How do you determine the scope of the per-list lock? Do you add a lock to every single data structure that you are required to grab before reading or modifying it? If you require the programmer to do it, you can easily get race conditions which will only show up once in a blue moon causing incorrect results or corruption at worst - something Python's GIL guaranteed not to happen (as long as you didn't do anything risky in your C extension). Is there any solution that doesn't use purely functional data structures?
Re:Solving multi-core Python by JoshTriplett on Friday July 10, 2015 @12:16PM (#9864818)
That's exactly why the approach proposed in this article potentially makes sense: run independent interpreters in different threads, and make all data sharing explicit. Then, anything shared between threads will need to know how to handle that, and anything that doesn't advertise that it's safe to share gets a lock around its use.