Python Threading, Threads Do Not Close
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. #!/usr/bin/env python import socket i
Solution 1:
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
Solution 2:
the_thread.setDaemon(true)
, see http://docs.python.org/library/threading.html#threading.Thread.daemon
Solution 3:
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.
Post a Comment for "Python Threading, Threads Do Not Close"