11 Comments
- nitsuj, on 10/12/2007, -0/+2Using native threads will eventually grind to a halt in any language as more time gets spent context switching than actually doing any work. The figure is typically stated at around 500 threads.
Adopt asynchronous techniques. Python has library support for that and I believe Twisted is built upon it.
Alternatively, for ultra concurrency programming, take a look at Erlang. - jesusphreak, on 10/12/2007, -0/+2If you are really interested in threading/concurrency/etc in Python, you are best off checking out Stackless Python. It is basically an extension to the language that does all these things very well.
- johnbmull, on 10/12/2007, -1/+2I find it hard to understand why Python doesn't do thread locking well. It does so much else so well that this seems like it would have been addressed. Heck, even Microsoft does thread locking in Visual Basic of all tools. Can somebody verify this problem/lack of ability in Python, up to Python 2.5?
"The world is not round - it is flat, or even two dimensional. Thanks to the Internet, everthing is either here or there." - milezteg, on 10/12/2007, -0/+1Wow great comments. If Python is not well suited for threaded programming, what would someone recommend for building an application to function like in the article? PHP at the command line? C?
- beuno, on 10/12/2007, -2/+3Nothing fancy but very clearly laid out.
- dlsspy, on 10/12/2007, -1/+1I don't think it's a good example of threaded programming. This shouldn't be a multithreaded application for much the reason the author states:
"With 1000 threads your app will likely either run out of memory or get so bogged down in context switching it'll take forever"
So, don't do it that way, just use one thread and async IO. 1,000 goes from being a large number to a small number. You can still use the same sort of throttling techniques to make it smaller, but the resource utilization will be much less all around, and it'll be safer (concurrent programming is hard -- hardly anyone gets it right).
This would be a great example of how to use twisted in python. It's also how HTTP requests work in Cocoa when doing MacOS X programs. - ridiculoufish, on 10/12/2007, -2/+2Python's threading support is miserable because of the global interpreter lock (http://docs.python.org/api/threads.html). Only one thread can be doing anything Python-y at once; this makes threads useless for concurrency, with the exception of I/O (which is what this article is about). I would say that the lack of thread safety in the interpreter is one of the most humiliating problems in Python.
- Mopatop, on 10/12/2007, -0/+0The problem is that the intepreter, or perhaps some extensions, aren't thread-safe. Adequate locking to solve this problem has been proposed and successfully implemented, however it turned out to be slower than the current implementation. Go figure.
- Vircom, on 10/12/2007, -0/+0good one
- theworldisround, on 10/12/2007, -11/+1OH SNAP!
http://houseohsnap.ytmnd.com/


What is Digg?
The Digg Toolbar for Firefox lets you Digg, submit content, and keep track of Digg even when you're not on the Digg site. Download the official