a very newbie question about threading

Jeremy Bowers jerf at jerf.org
Sat Nov 13 04:39:19 EST 2004


On Fri, 12 Nov 2004 16:29:53 -0800, Chris Patton wrote:

> Hey Everyone. 
> 
> I've recenently stumbled upon a concept known as "threading". Can
> anyone tell me what this IS and how it is used, or show me where I can
> get information about this?

Chris S. gave you the bare-bones basic.

I'd add that with no insult intended, "threading" and "very newbie" do not
go together well. Threading is the most common source of the notorious
"heisenbug", that randomly appears and disappears, resisting capture and
elimination by even the best of 'em. It's a complicated topic that gives
even the most expert programmers pause. I'm not exaggerating in the
slightest.

Generally, unless you *know* you need them, you don't, and there are ways
around using threads. Threads are kind of like the old "goto" statements;
it isn't that the idea of "goto" is intrinsically bad, it is just that
without discipline they rapidly become more problem than solution. So
instead of "goto", we use certain special cases of them, like function
calls and loops, that behave much more nicely. Most thread uses can
equally well be satisfied with certain other "special cases" that are much
less dangerous, like the "async" module for processing multiple incoming
files(/sockets/pipes whatever), or firing off seperate processes for long
running computations.

That said, I have used them when they were the best tool for the job. But
raw threads scare me every time.




More information about the Python-list mailing list