10 from nebula3.Exception
import (
12 NotValidConnectionException,
15 from nebula3.data.ResultSet
import ResultSet
17 from nebula3.logger
import logger
21 def __init__(self, connection, auth_result: AuthResult, pool, retry_connect=
True):
22 self.
_session_id_session_id = auth_result.get_session_id()
27 self.
_pool_pool = pool
35 :param params: parameter map
39 raise RuntimeError(
'The session has been released')
41 start_time = time.time()
43 end_time = time.time()
46 all_latency=int((end_time - start_time) * 1000000),
49 except IOErrorException
as ie:
50 if ie.type == IOErrorException.E_CONNECT_BROKEN:
51 self.
_pool_pool.update_servers_status()
54 logger.warning(
'Retry connect failed')
55 raise IOErrorException(
56 IOErrorException.E_ALL_BROKEN, ie.message
61 end_time = time.time()
64 all_latency=int((end_time - start_time) * 1000000),
80 """execute statement and return the result as a JSON string
81 Date and Datetime will be returned in UTC
111 "execDurationInUs": 0,
112 "totalDurationInUs": 0,
118 "conditionNodeId": -1
125 "optimize_time_in_us": 0
137 :param stmt: the ngql
143 """execute statement and return the result as a JSON string
144 Date and Datetime will be returned in UTC
174 "execDurationInUs": 0,
175 "totalDurationInUs": 0,
181 "conditionNodeId": -1
188 "optimize_time_in_us": 0
200 :param stmt: the ngql
201 :param params: parameter map
205 raise RuntimeError(
'The session has been released')
211 except IOErrorException
as ie:
212 if ie.type == IOErrorException.E_CONNECT_BROKEN:
213 self.
_pool_pool.update_servers_status()
216 logger.warning(
'Retry connect failed')
217 raise IOErrorException(
218 IOErrorException.E_ALL_BROKEN, ie.message
229 """release the connection to pool, and the session couldn't been use again
240 """ping at connection level check the connection is valid
242 :return: True or False
249 """ping at session level, check whether the session is usable"""
250 resp = self.
executeexecute(
r'RETURN "NEBULA PYTHON SESSION PING"')
251 if resp.is_succeeded():
255 'failed to ping the session: error code:{}, error message:{}'.format(
256 resp.error_code, resp.error_msg
261 def _reconnect(self):
264 conn = self.
_pool_pool.get_connection()
268 except NotValidConnectionException:
275 def _idle_time(self):
276 """get idletime of connection
282 return (time.time() - self.start_use_time) * 1000
285 """sign out the session"""
287 raise RuntimeError(
'The session has been released')
def execute_json_with_parameter(self, stmt, params)
def execute_json(self, stmt)
def execute_parameter(self, stmt, params)