Reputation:
What am I doing wrong ?
I simply need to kill both threads on Control+C.
def cleanup_stop_thread():
for thread in enumerate():
if thread.isAlive():
try:
self._Thread__stop()
except:
print(str(thread.getName()) + ' could not be terminated')
if __name__ == '__main__':
try:
threading.Thread(target = record).start()
threading.Thread(target = ftp).start()
except (KeyboardInterrupt, SystemExit):
cleanup_stop_thread();
sys.exit()
Upvotes: 1
Views: 1734
Reputation: 179717
Instead of trying to kill them on Ctrl+C, why don't you just make them daemon threads? Then they exit automatically when the main thread dies.
t1 = threading.Thread(target=record)
t1.daemon = True
t1.start()
t2 = threading.Thread(target=ftp)
t2.daemon = True
t2.start()
Upvotes: 6