Entry
How can I determine the number of threads that are running?
Jul 27th, 2000 00:50
unknown unknown, Aahz Maruch
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.