I have searched here extensively without much luck specifically in regards to my question.
Currently, my program has issues relating to file descriptor overflows (too many open files), nearly all of which are directing to my single log file. My program is set out in this fashion:
In my main:
# Initializes program log handler
log = Log()
log.setup_custom_logger('root')
logger = logging.getLogger('root')
Within the Log class:
def setup_custom_logger(self, name):
""" Sets base log handler for the program and log entry formatting """
# Create logger
logger = logging.getLogger(name)
log_level = self.getLogLevel()
logger.setLevel(log_level)
# Sets formatting, output file and handler
handler = logging.FileHandler(
os.getenv("HOME") + config.LOG_DIRECTORY + 'qtgtool.log')
handler.setFormatter(self.getFormat(log_level))
# Add handler to logger
logger.addHandler(handler)
And within any other class in the program this is called in their init:
logger = logging.getLogger('root')
I have checked, and there is only ever one FileHandler object and that is used by all classes. As such, I have no idea why it would create so many file descriptors of my log when class objects are created... Or am I missing something? Is it a case of too many class objects all with logging capabilities?
The output from the traceback:
IOError: [Errno 24] Too many open files:/path/to/file/being/read.txt
This corresponds with lsof -p indicating 1024 open files (nearly all my log file). As a side note, I have seen the options for increasing the open file count. I do not want to do this, as I find this to totally miss the point of trying to fix the problem.
Further debugging by using this class instead of logging.FileHandler():
class FHandler(logging.FileHandler):
def __init__(self, filename, encoding=None, delay=0):
logging.FileHandler.__init__(self, filename, 'w', encoding, delay)
def _open(self):
logging.FileHandler._open(self)
print 'Opened file'
This prints a single 'Opened file' to the console, whilst lsof (already, early stages of the program) presents over 100 log file references.
Many thanks and apologies for the deficiencies in my programming syntax.