how to know number of threads are running.

Aahz Maruch aahz at netcom.com
Wed Jul 26 09:46:50 EDT 2000


In article <397E524E.412FE123 at eSec.com.au>, Sam Wun  <swun at eSec.com.au> wrote:
>thanks

If you are using threading.py, and if you create all your threads using
threading.Thread() (or subclasses thereof), then you can use
threading.activeCount().  However, you should be aware of two caveats:

* The main thread that starts up the subthreads *does* count as a
thread, so your thread count is always one higher than your first guess.

* While occasionally useful for what I call "brute force" threading,
activeCount() is mostly useless in "real" threaded programs.  If you
really want to know how many threads are running, use some kind of
variable that you increment and decrement through a mutex.  But there
are usually no reasons other than debugging to do this.
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Zie is so far from a clue that it would take a sub-light vessel several
years to reach one.  --Aahz



More information about the Python-list mailing list