Changeset 6968 for lliurex-statistics


Ignore:
Timestamp:
Mar 7, 2018, 10:41:59 AM (21 months ago)
Author:
mabarracus
Message:

Merge some changes from python2 implementation

Location:
lliurex-statistics/trunk/fuentes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lliurex-statistics/trunk/fuentes/debian/changelog

    r6941 r6968  
     1lliurex-statistics (0.5.3) xenial; urgency=medium
     2
     3  * Merge some changes from python2 implementation
     4
     5 -- M.Angel Juan <m.angel.juan@gmail.com>  Wed, 07 Mar 2018 10:37:55 +0100
     6
    17lliurex-statistics (0.5.2.3) xenial; urgency=medium
    28
  • lliurex-statistics/trunk/fuentes/lliurex-statistics.install/usr/sbin/analytics

    r6941 r6968  
    6161
    6262if MODE == 'PROCEDURAL':
    63     from multiprocessing import Process, Manager
     63    from multiprocessing import Process, Manager, get_logger
    6464    str_formatter = '(%(processName)s)'
    6565if MODE == 'THREADED':
    6666    from multiprocessing.dummy import Process, Manager
     67        from multiprocessing import get_logger
    6768    str_formatter = '(%(threadName)s)'
    6869
     
    179180
    180181def init_logging(config):
    181     global DEBUG, log
    182 
     182    global DEBUG, log, loglevel
     183
     184    mpl = get_logger()
     185    mpl.setLevel(loglevel)
     186    for hdl in log.handlers:
     187        mpl.addHandler(hdl)
    183188    if get_var_value('DEBUG', config):
    184189        DEBUG = True
     
    313318
    314319        fp = subprocess.Popen(['tail', '-F', logfilename], stdout=subprocess.PIPE, stderr=open(os.devnull, 'w'))
     320        glob['monitor_pid'] = fp.pid
    315321    except Exception as e:
    316322        log.critical('Error initializing {} read, {}'.format(logfilename, e))
     
    325331                log.error('Dead subprocess monitoring {}'.format(logfilename))
    326332                fp = subprocess.Popen(['tail', '-F', logfilename], stdout=subprocess.PIPE, stderr=open(os.devnull, 'w'))
     333                glob['monitor_pid'] = fp.pid
    327334            else:
    328335                line = bin_to_ascii(fp.stdout.readline()).strip()
     
    466473    log.info("Starting analytics")
    467474    log.info('Initialization with release={} flavour={} proxy={}'.format(release,flavour,proxy))
    468    
     475
    469476    mgr = Manager()
    470477    glob = mgr.dict()
     
    736743
    737744def interrupt(*args, **kwargs):
    738     global glob, log, THREADS
     745    global glob, log, THREADS, mgr
    739746
    740747    log.info('Interrupting analytics')
     748   
    741749    try:
    742750        clean_and_send()
    743751        try:
    744752            glob['TERMINATE'] = True
    745         except:
    746             log.error('Requested kill the program')
     753            os.kill(glob['monitor_pid'],signal.SIGKILL)
     754        except Exception as e:
     755            log.error('Requested kill the program {}'.format(e))
    747756            sys.exit(1)
    748757        for x in THREADS:
    749758            THREADS[x].join()
     759            log.info('Interrupt: Joined {} {}'.format(x))
    750760
    751761    except Exception as e:
     
    878888        CONFIG = init_config()
    879889    except Exception as e:
    880         print('Error initializing config analytics {}'.format(e), file=sys.stderr)
     890        log.error('Error initializing config analytics {}'.format(e))
    881891        sys.exit(1)
    882892    try:
    883893        init_logging(CONFIG)
    884894    except Exception as e:
    885         print('Error initializing logging analytics {}'.format(e), file=sys.stderr)
     895        log.error('Error initializing logging analytics {}'.format(e))
    886896        sys.exit(1)
    887897
     
    913923
    914924    log.debug('End main')
    915     ended = False
    916     while not ended:
    917         for t in THREADS:
    918             THREADS[t].join()
    919             if THREADS[t].is_alive():
    920                 ended = False
    921                 break
    922             else:
    923                 ended = True
    924                 continue
     925    for t in THREADS:
     926        THREADS[t].join()
     927        log.info('Joined {}'.format(t))
     928    try:
     929        mgr.shutdown()
     930    except:
     931        pass
    925932
    926933    log.info('Exitting analytics')
Note: See TracChangeset for help on using the changeset viewer.