from nebula3.gclient.net import ConnectionPool from nebula3.Config import Config class NebulaConn: def initConnect(self, host, port, username, password, graphSpace): # 定义配置 config = Config() config.max_connection_pool_size = 10 # 初始化连接池 connection_pool = ConnectionPool() # 如果给定的服务器正常,则返回true,否则返回false。 status = connection_pool.init([(host, port)], config) # 用户名与密码 session = connection_pool.get_session(username, password) session.execute('USE %s' %(graphSpace)) return session, connection_pool def releaseConnectionPool(self, connection_pool): connection_pool.close() def releaseSession(self, session): session.release()