Why can’t a crawler setDeamon(False) cause the program to quit in python?

The train of thought has gone awry.

If I put t.daemon = False, why does the program stop after print ‘done’, Ctrl-C cannot exit, and t.daemon = True exits directly after printing

My understanding is that Ctrl-C can only receive singal of the main thread, and then the main thread exits and cannot receive singal naturally. But this should not happen, because all my sub-threads have already done task_done. So what is the reason why the program card is here now?

When the program is running, a main thread is executed. If the main thread creates another sub-thread, the main thread and the sub-thread will split up and run separately. If the main thread wants to exit, it will check whether the sub-thread is completed. If the child thread is not completed, the main thread waits for the child thread to complete before exiting. However, sometimes what we need is to exit with the main thread as long as the main thread is finished, regardless of whether the sub-thread is finished or not, and then we can use the setDaemon(True) method.

You have quoted it and the explanation is very clear. The reason for not exiting is that the newly created process is still running.

The purpose of setdaemon is to mark a new thread. Only the thread marked Daemon will end with the exit of the parent thread. This is the principle.

In addition, your child thread is a dead loop, and no jump statements are found, so this often continues to run regardless of whether your task is finished or not.