Changeset 11:d6d0b170ac48 in livinglogic.python.tipimaid

Show
Ignore:
Timestamp:
11/19/08 19:54:18 (10 years ago)
Author:
Nikolas Tautenhahn <nik@…>
Branch:
default
Message:

added signal handling for SIGHUP, SIGTERM, SIGINT, SIGQUIT

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • liaalh.py

    r10 r11  
    33 
    44 
    5 import sys, os, datetime, errno, bisect, re, gzip 
     5import sys, os, datetime, errno, bisect, re, gzip, signal 
    66 
    77 
     
    7979 
    8080    def run(self): 
    81         while True: 
    82             line = self.stream.readline() 
    83             datestring = self.re_find_date.findall(line)[0] 
    84             utctime = self.apachedate2utc(datestring) 
    85             (server, data) = line.split(None, 1) 
    86             self.add(LogLine((utctime, server, data))) 
     81        try: 
     82            while True: 
     83                line = self.stream.readline() 
     84                datestring = self.re_find_date.findall(line)[0] 
     85                utctime = self.apachedate2utc(datestring) 
     86                (server, data) = line.split(None, 1) 
     87                self.add(LogLine((utctime, server, data))) 
     88        except Exception, exc: 
     89            self.flush() 
     90            raise 
     91 
     92    def sighandler(self, signum, frame): 
     93        self.flush() 
     94        sys.exit(1) 
    8795 
    8896 
     
    103111        return 1 
    104112    buf = Buffer(pattern=args[0], gzip_logs=options.gzip, buffertime=300) 
     113    signal.signal(signal.SIGHUP, buf.sighandler) 
     114    signal.signal(signal.SIGTERM, buf.sighandler) 
     115    signal.signal(signal.SIGINT, buf.sighandler) 
     116    signal.signal(signal.SIGQUIT, buf.sighandler) 
    105117    buf.run() 
    106118