I cannot catch the INT signal in the main thread, please advise me how to fix the problem. I wish that the sleep method could be interrupted by CTRL+C, but it waits till the timer is ended..
import pygtk
pygtk.require('2.0')
import gtk
import time
import urllib2
import re
import signal
import sys
import __main__
from time import ctime, strftime, localtime
from threading import Thread
myThread = None
class MyThread(Thread):
def __init__(self, filename):
Thread.__init__(self)
self.filename = filename;
self.terminate = False
def StopProcess(self):
self.terminate = True
def run(self):
while self.terminate <> True:
time.sleep(5)
self.terminate = True
def SignalHandler(signum, frame):
if (myThread <> None):
myThread.StopProcess()
sys.exit()
if __name__ == "__main__":
signal.signal(signal.SIGINT, SignalHandler)
myThread = MyThread("aaa")
myThread.start()