Summary of threading for experienced non-Python programmers?
hdante at gmail.com
Mon Mar 31 00:22:42 CEST 2008
On Mar 28, 11:52 am, s... at pobox.com wrote:
> I'm having trouble explaining the benefits and tradeoffs of threads to my
> coworkers and countering their misconceptions about Python's threading model
> and facilities. They all come from C++ and are used to thinking of
> multithreading as a way to harness multiple CPU cores for compute-bound
> processing. I also encountered, "Python doesn't really do threads" today.
> I don't need pointers to the relevant documentation sections. A bit of
> googling didn't turn up much about threading beyond tutorial introductions.
> I'm looking for something which will explain the rationale for using threads
> in Python to someone who is experienced with multithreading in other
> languages (like C/C++). Maybe a compare-and-contrast sort of document?
I think you are having trouble because threads suck. They are the
worst way of dealing with concurrency that exists (unfortunately they
are the fastest also) :-).
Threads are bad because, by construction, code may be subject to non-
trivial hazards. There are other ways of dealing with concurrency that
doesn't have this problem, like event-driven programming. I think
threads are so bad, that when I left my job at a company that
developed for PDAs, I told my team: "whenever you have an argument
about how to make multitasking, you may count my vote against using
If you really need to use threads, then use design patterns that make
threads behave like message passing systems (I believe there were the
"monitor model" or the "actor model" or something).
If you need threads because you need speed, then use a recent JIT-
compiled language, like Java or C#. In general, you may use C or C++
also, but there are a few obscure problems with them because they
weren't defined with threads in mind.
If you just would like to use "multitasking" as a programming
paradigm, try Twisted, or switch to stackless python (then write an
blog about your findings). :-)
More information about the Python-list