Installing Gentoo web server
Sorry, this entry is only available in Czech.
Sorry, this entry is only available in Czech.
I have written some Python script using Trac API for handling tickets in this bug system. Unfortunately after some time running, it failed with error: IOError: [Errno 24] Too many open files.
I was checking my code and everything was OK. So I downloaded excellent tool called “Process Explorer“. In this program, you can watch any process.
In menu: View -> Lowe pane view -> Handles you can view all open handles by your program. There I found out, that there is bug in Trac, which is not closing the file handle of log file even when shutdown() function is called.
To fix it, it is necessary next to calling env.shutdown() also call this code:
if hasattr(env.log, '_trac_handler'): hdlr = env.log._trac_handler env.log.removeHandler(hdlr) hdlr.close()
class MyFormatter(logging.Formatter): def __init__(self, fmt=None, datefmt=None, encoding='windows-1250'): logging.Formatter.__init__(self, fmt, datefmt) self.encoding = encoding def formatException(self, ei): r = logging.Formatter.formatException(self, ei) if type(r) in [types.StringType]: r = r.decode('windows-1250', 'replace') # Convert to unicode return r def format(self, record): t = logging.Formatter.format(self, record) if type(t) in [types.UnicodeType]: t = t.encode(self.encoding, 'replace') return t def prepareFileAndConsoleLogging(soubor, urovenSoubor=None, urovenKonzole=None): # http://docs.python.org/library/logging.html global logging, libLogger if urovenSoubor == None: urovenSoubor = logging.DEBUG if urovenKonzole == None: urovenKonzole = logging.INFO #logging.basicConfig(level=urovenSoubor) # Soubor fileH = logging.FileHandler(soubor, 'a') fileH.setLevel(urovenSoubor) formatterF = MyFormatter( fmt='%(asctime)s|%(levelname)-8s|%(name)s|%(message)s|%(filename)s|%(funcName)s|%(lineno)d', encoding='windows-1250') fileH.setFormatter(formatterF) logging.getLogger('').addHandler(fileH) logging.getLogger('').setLevel(urovenSoubor) # Konzole console = logging.StreamHandler() console.setLevel(urovenKonzole) formatter = MyFormatter( fmt='%(name)s: %(message)s', encoding='cp852') console.setFormatter(formatter) logging.getLogger('').addHandler(console) libLogger.info(u'UNICODE: Logování inicializováno (diakritika: ščřžýáíé)') libLogger.info('STRING: Logování inicializováno (diakritika: ščřžýáíé)') libLogger.debug(u'Debug')
Při psaní skriptíku na generování zátěže na HTTP se mi po pár minutách začala vracet chyba “Address already in use”. Tento problém je hezky popsán zde i s perfektními skripty na odzkoušení (bohužel bez řešení). Read more…