Я хочу останавливать потоки, когда принимаю Ctrl-C
, поэтому, согласно некоторым документам, я пытался:
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
но я считаю, что это также означает threads will stop after 10 seconds
, это не может удовлетворить мои требования. Поэтому я удаляю 10
из кода:
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
то не могу убить программу с Ctrl-C
.
Итак, как я могу элегантно убить все потоки?