Testuję wątki Pythona za pomocą następującego skryptu:
import threading
class FirstThread (threading.Thread):
def run (self):
while True:
print 'first'
class SecondThread (threading.Thread):
def run (self):
while True:
print 'second'
FirstThread().start()
SecondThread().start()
Działa w Pythonie 2.7 na Kubuntu 11.10. Ctrl+ Cgo nie zabije. Próbowałem też dodać obsługę sygnałów systemowych, ale to nie pomogło:
import signal
import sys
def signal_handler(signal, frame):
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
Aby zabić proces, zabijam go przez PID po wysłaniu programu do tła z Ctrl+ Z, co nie jest ignorowane. Dlaczego Ctrl+ Cjest tak uporczywie ignorowany? Jak mogę to rozwiązać?