title: 2 threads each serving 2 different HTTP Server, will not stop after a given duration
body: <p>So I have spent at least a couple of days on this problem. </p>
  
  <p>I would like to have 2 threads HTTP server each serving two different IP:ports.<br>
  I open a FF and navigate to either say: <a href="http://196.64.131.250:8001/" rel="nofollow">http://196.64.131.250:8001/</a>  or <a href="http://196.64.131.250:8002" rel="nofollow">http://196.64.131.250:8002</a>   and it should do a GET.  </p>
  
  <p>Also I like my threads or program itself stop after a given duration from command line say 5 sec.
  I have done everything I could, even tried SIGAlarm and variable "keepRunning" which gets changed by a third thread after duration , but my program does Not stop. What am I doing wrong please. </p>
  
  <p>note that I have commented the daemon: i.e (ZhttpThread[1-2].daemon = True)</p>
  
  <p>if I dont comment it my threads stop right away. I want my HTTP server threads continue servicing, and if the duration DUR expires , then the program stops or threads stop. </p>
  
  <pre><code>import SimpleHTTPServer, SocketServer, logging, cgi, sys, signal, threading, time
  import subprocess as sub
  
  keepRunning = True
  origTime = int(time.time())
  
  class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
      def do_GET(self):
          logging.warning("======= GET STARTED =======")
          getHdr = self.headers
          SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
          getHdr = self.headers
          print(', '.join((getHdr)))
          #if ("accept-encoding" in getHdr):
          if ("accept-encoding" in (', '.join((getHdr)))):
              print ('Test Passed ---------------')
              signal.alarm(1)
  
  class threadWithTO(threading.Thread):
      def __init__(self, thID, ip, port, timeout):
          threading.Thread.__init__(self)
          self.ip = ip
          self.port = port
          self.handler = ServerHandler
          self.httpd = SocketServer.TCPServer((self.ip, self.port), self.handler)
      def run(self):
          print (self.httpd)
          #self.httpd.serve_forever()
          if (keepRunning == True):
             self.httpd.handle_request()
          else:
             self._stop.set()
      def Run(self):
          self.start()
  
  def timeHandler(signum, frame):
      print('Times up', signum)
      sys.exit()
  
  def timeChkr( threadName, dur, t1, t2):
    print (origTime)
    print ('Begin Timer thread')
    while True:
      nowTime = int(time.time())
      print (nowTime)
      delta = nowTime - origTime
      if (delta &gt;= dur):
          keepRunning = False
          t1.stop()
          t2.stop()
      else:
          time.sleep(1)
  
  def main():
      #signal.signal(signal.SIGALRM, timeHandler)
      #signal.alarm(DUR)
  
      origTime = int(time.time())
      ZhttpThread1 = threadWithTO("thread1", I, PORT, DUR)
      ZhttpThread2 = threadWithTO("thread2", I, (int(PORT)+1), DUR)
  
      t = threading.Thread(target=timeChkr, args = ("thread3",DUR))
      t.daemon = True
      t.start()
  
      #ZhttpThread1.daemon = True
      #ZhttpThread2.daemon = True
  
      ZhttpThread1.Run()
      ZhttpThread2.Run()
  </code></pre>