I want to stop threads when accept Ctrl-C
, so according to some documents, I tried:
try:
threads = [t.join(10) for t in threads if t is not None and t.isAlive()]
except KeyboardInterrupt:
print "Ctrl-c received! Sending kill to threads..."
for t in threads:
t.kill_receives = True
# some other process
but I find this also means threads will stop after 10 seconds
, this can not meet my requirements. So I remove 10
from code:
try:
threads = [t.join() for t in threads if t is not None and t.isAlive()]
except KeyboardInterrupt:
print "Ctrl-c received! Sending kill to threads..."
for t in threads:
t.kill_receives = True
# some other process
then I can not kill the program with Ctrl-C
.
So how can I kill all threads elegant?