thread conditional code

Ken Peek Peek at LVCM.comNOSPAM
Sun Apr 15 12:24:52 EDT 2001


It's better to be safe than sorry.  What if you want to re-use the code in the
future?  What if someone else grabs your code snippet on a big project, and uses
it with threads?  You're worried about performance?  Forget it!  Most computers
these days are so much faster than the memory or I/O, that performance is not an
issue.  I have an Athlon 500Mhz-- very slow by today's standards, but you know
what?  I have never had a performance issue come up (in regards to how fast code
executes.)  If you are doing something that requires extreme processing power
(say, modeling the weather of the entire planet) then you probably are using the
wrong hardware, and should probably think about using a language that compiles
to native code.  Python is for the other 99.999% of computer problems where
"bean counting" CPU cycles is just a waste of time. ;-)  (Oh! Sorry!-- I Just
HAD to throw the pun in!)

P.S.-- Don't worry-- Be Happy!

"Robin Becker" <robin at jessikat.fsnet.co.uk> wrote in message
news:2AVsHJA7kE26EwmR at jessikat.fsnet.co.uk...
> In article <mailman.987247039.25991.python-list at python.org>, Tim Peters
> <tim.one at home.com> writes
> ...
> >> That way I could conditionally lock access to contentious
> >> variables and avoid thread overhead when not needed.
> >
> >I'm afraid the only way to be sure of that is to build Python without
> >threads -- only the OS knows how many threads exist at any given time.  If
> >it's *possible* for another thread to pop into existence in your Python code,
> >then you have to lock even before it pops into existence, lest it pop into
> >existence "in the middle" of one of your critical sections that you cleverly
> >avoided locking, and then enter the (unlocked) critical section at the same
> >time.  If the threads you deal with are too well behaved for that, then
> >there's no need for any locks at all <wink>.
> >
> >trying-to-cheat-locks-is-the-#1-cause-of-thread-disasters-ly y'rs  - tim
> >
> >
> if only one (the main) thread exists at the beginning of my critical
> section and I'm not creating any threads how could one pop into
> existence?
>
> If python threads aren't initialised and I don't do the initialisation
> who else can do it? What I'm really asking is how to avoid initialising
> the threading checks without losing the possibility of locking.
>
> I assumed probably wrongly that there is an overhead to running multiple
> threads because of the ceval thread switch tests; after scanning the
> source code I suspect you have the thread switch overhead whether or not
> the thread stuff is initialized and then it makes no sense to avoid
> using it.
> --
> Robin Becker





More information about the Python-list mailing list