def _cleanner(): try: currtime = time.time() for (k, v) in _cache_data.items(): if currtime - v[1] > _cache_life: _cache_data.pop(k) continue except: Common.outerror(Common.get_exception_info())
msg = u'[%s] %s' % (Common.get_unicode(logid), Common.get_unicode(msg)) Common.outerror(msg) if __name__ == '__main__': globals()['_DEBUG'] = Common.check_debug() Common.init_run_user() Common.init_pid_file('sizequerier.pid') Common.init_logger('SizeQuerier', len(sys.argv) > 1, _DEBUG) Common.Core.check_initialization() Common.init_cfg_default() EXIT_CODE = 0 Common.outinfo('program start') try: gevent.signal(signal.SIGTERM, signal_handle, 'sigterm') gevent.signal(signal.SIGALRM, signal_handle, 'sigalrm') gevent.spawn(cache_cleaner) server = StreamServer(('127.0.0.1', 10029), main) server.serve_forever() except KeyboardInterrupt: signal_handle('sigint') except SystemExit: e = None EXIT_CODE = e.code except: Common.outerror(Common.get_exception_info()) EXIT_CODE = 1 Common.outinfo('program quit') sys.exit(EXIT_CODE)