If you can get a handle to the main thread, you can call is_alive()
on it.
Alternatively, you can call threading.enumerate()
to get a list of all current live threads, and check if there is a main thread there.
Or, if this is not possible, you can check if the child thread is the only remaining non-daemon.
source share