Tuesday, 15 December 2015

Python: Get main thread object

'threading.main_thread()' returns the main thread object.


MyThread.py
import threading

mainThread = threading.main_thread()

print("Is main thread alive : ", mainThread.is_alive())
print("Is main thread daemon thread : ", mainThread.isDaemon())

$ python3 MyThread.py 
Is main thread alive :  True
Is main thread daemon thread :  False



Previous                                                 Next                                                 Home

No comments:

Post a Comment