Skip to content
Browse files

Added fix for logrotate causing dangling file handlers . Closes #111

  • Loading branch information...
1 parent a5fd367 commit e1f67eda29855cecb202f9b72ed0a7169f2aa296 Nicholas Davidson committed Feb 5, 2013
Showing with 12 additions and 6 deletions.
  1. +9 −6 pybit-client
  2. +3 −0 pybitclient/__init__.py
View
15 pybit-client
@@ -36,6 +36,7 @@ import daemon
from pybit.daemonlogger import LoggingDaemonContext, FileLikeLogger
import time
import logging
+from logging.handlers import WatchedFileHandler
from pybitclient import PyBITClient
from pybitclient.debianclient import DebianBuildClient
from pybitclient.subversion import SubversionClient
@@ -64,9 +65,12 @@ def run(settings) :
sys.exit (os.EX_OSERR)
def getDaemonLogger (filePath, format = None) :
- FORMAT = format or '%(asctime)s %(msg)s'
- logging.basicConfig(filename=filePath, format=FORMAT, level=logging.DEBUG)
- return logging.getLogger()
+ logger = logging.getLogger()
+ logger.setLevel(logging.DEBUG)
+ watchedHandler = WatchedFileHandler(filePath)
+ watchedHandler.setFormatter(logging.Formatter(format or '%(asctime)s %(msg)s'))
+ logger.addHandler(watchedHandler)
+ return logger
if __name__ == '__main__':
parser = optparse.OptionParser()
@@ -134,8 +138,7 @@ if __name__ == '__main__':
context.loggers_preserve=[testLogger]
context.signal_map = {
signal.SIGTERM: signal_handler,
- signal.SIGHUP: signal_handler,
- signal.SIGUSR1: None,
+ signal.SIGHUP: signal_handler
}
logging.debug ("Daemonised")
else :
@@ -149,7 +152,7 @@ if __name__ == '__main__':
if settings == {}:
logging.debug ("No settings found - exiting")
sys.exit(os.EX_OSERR)
- if 'configured' in settings and settings.configured == False:
+ if 'configured' in settings and settings['configured'] == False:
logging.debug ("Please configure your client.")
sys.exit(os.EX_OK)
View
3 pybitclient/__init__.py
@@ -415,16 +415,19 @@ def disconnect(self):
if self.command_chan:
#self.command_chan.basic_cancel("build_callback")
try:
+ logging.debug("Closing down command channel")
self.command_chan.close()
except socket.error :
pass
if self.message_chan:
#self.message_chan.basic_cancel("build_callback")
try:
+ logging.debug("Closing down message channel")
self.message_chan.close()
except socket.error :
pass
try :
+ logging.debug("Closing down rabbitmq connection")
self.conn.close()
except socket.error :
pass

0 comments on commit e1f67ed

Please sign in to comment.
Something went wrong with that request. Please try again.