5 ms·
Multithreading in Python is all uphill. In Python, any thread can store into anything at any time. By name, even, using "setattr". There's no thread-local data.
by Animats 9y ago
Multithreading in Python is all uphill. In Python, any thread can store into anything at any time. By name, even, using "setattr". There's no thread-local data. This implies excessive locking activity. That's why this guy is working so hard to do things that ought to be simple.
A few restrictions on the language would make it easier, but when this is suggested, Guido has a cow.
- nine_k 9y agoIs there a link explaining the suggestions succinctly?
- Animats 9y ago- Multiple interpreters with mostly non-shared data in the same process.[1]. - VecPy, for number-crunching.[2] - Newthreading, which I wrote in 2010.[3] [1] https://lwn.net/Articles/650489/ https://lwn.net/Articles/650489/ [2] https://www.andrew.cmu.edu/user/dfarrow/proposal.html https://www.andrew.cmu.edu/user/dfarrow/proposal.html [3] http://www.animats.com/papers/languages/newthreadingintro.html http://www.animats.com/papers/languages/newthreadingintro.ht...
- simcop2387 9y agoTo be fair at least towards #1, that's a really difficult one to get right. Perl has had that kind of threading for a long time and it's almost always considered a bad decision to try to use them. I'm sure it could be done better, but perl did it via a complete copy on write setup in order to create the mostly non-shared data. But you end up with a lot of locking and other contention for the shared data because there's no good way to expose the fact that it's shared and changing it requires such restrictions. Instead the method usually used is to take advantage of most OS's built in COW when forking a new process and communicating via sockets, or some other method instead that forces you to deal with the limitations (copying data, or if you used shared memory you have to do explicit sharing and locking/serialization yourself).
- benhoyt 9y ago"Guido has a cow". Hmmm, or maybe he knows this would be mean huge, backwards-incompatible changes to the language's dynamic nature, and especially after the experience with the changes (I think much lesser ones compared to this) from Python 2 to Python 3, he's very wary of that. Still, if you were going to propose "a few restrictions on the language" to make it less dynamic and easier to do multi-threading / optimization, what would they look like?
- VectorLock 9y agoFrom seeing the "Status of the Gilectomy" talk at PyCon it sounded more like the big blocker is not breaking the C API too bad. Now if somebody suggested a Python 4 with a totally backwards incompatible but thread-safe C API now that I could see him having a cow over (even though I like that idea)
- omginternets 9y ago>when this is suggested, Guido has a cow. Like what? My first reaction is to think "and he's [probably] right!" Python's added value is it's very rich and flexible object model. Imposing restrictions on the object model is robbing Peter to pay Paul in an environment where Peter is more important, albeit for historical reasons.