Python threading, threads do not close

后端 未结 3 1478
情话喂你
情话喂你 2020-12-20 23:12

I have a Python program and when I exit the application with Ctrl-c, the script does not close. My process still shows in running processes.

#!/         


        
相关标签:
3条回答
  • 2020-12-20 23:20

    I was unable to kill my python sub process because I had set the shell=True option in the process.Popen command. I removed shell=True and then I could kill it.

    If the subprocess is a shell, then you will have to kill the things it is running before the shell will end itself.

    0 讨论(0)
  • 2020-12-20 23:29

    You need to make the thread a daemon thread. To do this add the following line after you call the Thread's init

    self.setDaemon(True)
    

    A program will exit when only daemon threads are left alive, the main thread is non-daemonic of course

    0 讨论(0)
  • 2020-12-20 23:34

    the_thread.setDaemon(true), see http://docs.python.org/library/threading.html#threading.Thread.daemon

    0 讨论(0)
提交回复
热议问题