warnings.simplefilter(action='ignore', category=FutureWarning) # ignore future warnings log = None if log is None: if is_server(): # by shell script log = LogUtil.get_logger(sys.argv[0], level=logging.INFO, console_mode=True, multiprocess=False) # global log elif is_pycharm_remote(): # remote gpu server log = LogUtil.get_logger(sys.argv[0], level=logging.DEBUG, console_mode=True, multiprocess=False) # global log # console_mode=True for jupyter else: # my macbook log = LogUtil.get_logger(None, level=logging.DEBUG, console_mode=True) # global log ################################################# # DB ################################################# MONGO_URL = r'mongodb://%s:%s@%s:%s/%s?authMechanism=MONGODB-CR' % ('root', os.getenv('MONGODB_PASSWD'), 'db-local', '27017', 'admin') MYSQL_URL = {'host': db_hostname(), 'user': '******', 'passwd': os.getenv('MYSQL_PASSWD'), 'db': 'kr_nlp'} ################################################# # tensorboard log dir ################################################# TENSORBOARD_LOG_DIR = os.path.join(os.getenv("HOME"), 'tensorboard_log') # log.info('TENSORBOARD_LOG_DIR: %s' % TENSORBOARD_LOG_DIR) if not os.path.exists(TENSORBOARD_LOG_DIR): os.makedirs(TENSORBOARD_LOG_DIR) ################################################# # nlp4kor-ko.wikipedia.org ################################################# WIKIPEDIA_DIR = os.path.join(os.getenv('HOME'), 'workspace', 'nlp4kor-ko.wikipedia.org') WIKIPEDIA_CORPUS_DIR = os.path.join(WIKIPEDIA_DIR, 'corpus') if not os.path.exists(WIKIPEDIA_CORPUS_DIR):
log = LogUtil.get_logger(None, level=logging.INFO, console_mode=True) # global log else: # batch mode log = LogUtil.get_logger(sys.argv[0], level=logging.INFO, console_mode=False) # global log else: # gpu pc(batch job, ubuntu) log = LogUtil.get_logger( sys.argv[0], level=logging.INFO, console_mode=False ) # global log # console_mode=True for jupyter notebook MONGO_URL = r'mongodb://%s:%s@%s:%s/%s?authMechanism=MONGODB-CR' % ( 'root', os.getenv('MONGODB_PASSWD'), 'db-local', '27017', 'admin') MYSQL_URL = { 'host': db_hostname(), 'user': '******', 'passwd': os.getenv('MYSQL_PASSWD'), 'db': 'kr_nlp' } PROJECT_DIR = os.path.join(os.getenv("HOME"), 'workspace/nlp4kor') # log.info('PROJECT_DIR: %s' % PROJECT_DIR) DATA_DIR = os.path.join(PROJECT_DIR, 'data/') # log.info('DATA_DIR: %s' % DATA_DIR) if not os.path.exists(DATA_DIR): os.mkdir(DATA_DIR) TENSORBOARD_LOG_DIR = os.path.join(os.getenv("HOME"), 'tensorboard_log') # log.info('TENSORBOARD_LOG_DIR: %s' % TENSORBOARD_LOG_DIR)
port=6379, db=TEST_DB_NO, password=os.getenv('REDIS_PASSWD'), decode_responses=True, encoding='utf8'): pool = redis.ConnectionPool(host=host, port=port, db=db, password=password, decode_responses=decode_responses, encoding=encoding) return redis.Redis(connection_pool=pool) if __name__ == '__main__': _redis = RedisUtil.get_client(host=db_hostname(), decode_responses=False) li = [1, 2, 3] _redis.rpush('test_queue', pickle.dumps(li)) item = _redis.lpop('test_queue') print(pickle.loads(item)) _redis = RedisUtil.get_client(host=db_hostname(), decode_responses=True) print(_redis.info()) _redis.delete('test') _redis.hset('test', '1', 100) _redis.hset('test', '2', 200) _redis.hdel('test', '1') print(type(_redis.hkeys('test'))) _redis.set('test', 10) value = _redis.get('test') print(type(value), value)