Is there any way to know what threads are running using python threading module. With the following piece of code, I am able to get the Thread name, current thread, active thread count.
But my doubt here is ACTIVE_THREADS are 2 and the CURRENT THREAD is always "MainThread". What could be the other thread which is running at the back ground ?
import threading
import time
for _ in range(10):
time.sleep(3)
print("\n", threading.currentThread().getName())
print("current thread", threading.current_thread())
print("active threads ", threading.active_count())
MainThread
current thread <_MainThread(MainThread, started 11008)>
active threads 2
You can access all current thread objects using threading.enumerate()
, e.g.
for thread in threading.enumerate():
print(thread.name)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With