Starting threads -- solved
peter at engcorp.com
Wed Jan 29 20:27:56 CET 2003
Lukas Kubin wrote:
> You are right. I did access the "comp" (containg hostname) variable
> globally instead of use the form "classname.variablename" or "self.comp".
> Yes, it's a beginners' fault. Don't laugh, please :) I'll do it no more
It might be a beginner's fault, but it's also an expert's fault. The
only difference might be how often we make it, and how long it takes
to find. Anyone who's written enough code with threads would agree
that they, you, and I will _all_ make the same mistake again, probably
several times. :-)
Note that globals and threads almost never mix, and even if you're
sick of hearing people talk about "never use globals", writing a lot
of threaded code is a good way to break you of the bad habit.
(By the way, even putting it in as a class variable would be a problem,
since both threads are instances of the same class, so from their
points of view that value is still a global. Use the instance
variable to avoid trouble.)
> Thank anybody for trying to help me and sorry I've took your time.
Hey, that's what we're here for! Don't apologize. If we didn't have
some strange defect in our personalities that made us want to help
others, we wouldn't post... ;-)
More information about the Python-list