connction
from nebula3.gclient.net import ConnectionPool from nebula3.Config import Config
define a config
config = Config() config.max_connection_pool_size = 10
init connection pool
connection_pool = ConnectionPool()
if the given servers are ok, return true, else return false
ok = connection_pool.init([('127.0.0.1', 9669)], config)
option 1 control the connection release yourself
get session from the pool
session = connection_pool.get_session('root', 'nebula')
select space
session.execute('USE basketballplayer')
show tags
result = session.execute('SHOW TAGS') print(result)
release session
session.release()
option 2 with session_context, session will be released automatically
with connection_pool.session_context('root', 'nebula') as session: session.execute('USE basketballplayer') result = session.execute('SHOW TAGS') print(result)
close the pool
connection_pool.close()
在使用官方案例时会报错
Connect 10.113.36.125:9669 failed: Socket read failed: [Errno 104] Connection reset by peer
Traceback (most recent call last):
File "/home/chatgpt/m31660/Pycharm/nebula/insert_gcov_data.py", line 148, in
Could you provide more details? You can try the following:
- Eliminate network issues first
- Make sure your remote port is open (the address seems to be deployed on the server)
- Check whether the nebula-python version corresponds to the nebula graph version. You can refer to here.
If the problem still exists after eliminating the above problems. You are welcome to provide more details, and feel free to ask.