Python getting running Threads
You can use threading.enumerate() : Python documentation about it here
for thread in threading.enumerate():
print(thread.name)
threading.enumerate() can be used for getting the list of running threads (Thread objects). As per library reference, running threads imply
- All Thread objects that are currently alive, created using threading module
- Daemonic threads (whose presence doesn't prevent the process from exiting)
- Dummy thread objects created by current thread (Threads directly created from C code. They are always alive and daemonic and cannot be joined)
- Main Thread (Default thread in python)
It excludes Threads that are not yet started and already terminated.
You can use threading.active_count to get the length of the list returned by threading.enumerate