X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Ftheonering.py;h=f8a26f49da6f78d0b1ee29b70961fab37198f1a1;hp=23ad1ee4b18455f3601877482c898343ae59b7f5;hb=13e110dc28426fba921730b472a618ba5d51c6f5;hpb=f289412744a4bc95f9b06beb2ed3a1fa5df4bfb1;ds=sidebyside diff --git a/src/theonering.py b/src/theonering.py index 23ad1ee..f8a26f4 100755 --- a/src/theonering.py +++ b/src/theonering.py @@ -23,6 +23,7 @@ import os import sys import signal import logging +import logging.handlers import gobject import dbus.glib @@ -34,9 +35,6 @@ import constants import connection_manager -IDLE_TIMEOUT = 5000 - - def run_theonering(persist): linux_utils.set_process_name(constants.__app_name__) @@ -47,23 +45,26 @@ def run_theonering(persist): raise @gobject_utils.async - def quit(): + def on_quit(): manager.quit() mainloop.quit() def timeout_cb(): if len(manager._connections) == 0: logging.info('No connection received - quitting') - quit() + on_quit() return False if persist: shutdown_callback = None else: - gobject.timeout_add(IDLE_TIMEOUT, timeout_cb) - shutdown_callback = quit + gobject_utils.timeout_add_seconds( + connection_manager.TheOneRingConnectionManager.IDLE_TIMEOUT, + timeout_cb + ) + shutdown_callback = on_quit - signal.signal(signal.SIGTERM, quit) + signal.signal(signal.SIGTERM, lambda: on_quit) try: manager = connection_manager.TheOneRingConnectionManager(shutdown_func=shutdown_callback) @@ -73,6 +74,8 @@ def run_theonering(persist): mainloop = gobject.MainLoop(is_running=True) + gobject.threads_init() + dbus.glib.init_threads() while mainloop.is_running(): try: mainloop.run() @@ -88,20 +91,18 @@ def main(logToFile): raise telepathy_utils.debug_divert_messages(os.getenv('THEONERING_LOGFILE')) - if logToFile: - logging.basicConfig( - level=logging.DEBUG, - filename=constants._user_logpath_, - format='(%(asctime)s) %(levelname)s:%(name)s:%(message)s', - datefmt='%H:%M:%S', - ) - else: - logging.basicConfig( - level=logging.INFO, - format='(%(asctime)s) %(levelname)s:%(name)s:%(message)s', - datefmt='%H:%M:%S', - ) - logging.debug("telepathy-theonering %s-%s" % (constants.__version__, constants.__build__)) + logFormat = '(%(asctime)s) %(levelname)-5s %(threadName)s.%(name)s: %(message)s' + logging.basicConfig( + level=logging.DEBUG, + format=logFormat, + datefmt='%H:%M:%S', + ) + logging.raiseExceptions = True # Getting funky shutdown behavior, checking it out + rotating = logging.handlers.RotatingFileHandler(constants._user_logpath_, maxBytes=512*1024, backupCount=1) + rotating.setFormatter(logging.Formatter(logFormat)) + root = logging.getLogger() + root.addHandler(rotating) + logging.info("telepathy-theonering %s-%s" % (constants.__version__, constants.__build__)) logging.debug("OS: %s" % (os.uname()[0], )) logging.debug("Kernel: %s (%s) for %s" % os.uname()[2:]) logging.debug("Hostname: %s" % os.uname()[1])