There is a main thread during the script run, and if a child thread is created in the main thread, one of the following two situations may occur when the main thread ends depending on the Daemon property value of the child thread:
If the Daemon property of a child thread is false, the main thread will detect if the child thread ends at the end, and if the child thread is still running, the main thread waits for it to complete before exiting;
If the Daemon property of a child thread is true, the thread exits without checking the child thread at the end of the run, and all child threads with a value of true daemon end with the main thread, regardless of whether the run is complete or not.
The value of property daemon defaults to False and must be set before calling the start () method if modifications are required. It is also important to note that the above description does not apply to the interactive mode or script run mode in the idle environment, because the main thread in the environment is terminated only when it exits Python idle.
Turn from: 53899426
The role of daemon attributes in Python multithreaded programming