2

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?

roger
  • 9,063
  • 20
  • 72
  • 119
  • Or http://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python – stark Sep 06 '15 at 11:11

0 Answers0