in pyqldb/driver/qldb_driver.py [0:0]
def _get_session(self, start_new_session):
"""
This method will attempt to retrieve an active, existing session, or it will start a new session with QLDB if
none are available and the session pool limit has not been reached. If the pool limit has been reached, it will
attempt to retrieve a session from the pool until the timeout is reached.
:type start_new_session: bool
:param start_new_session: A boolean value to determine whether to start a new session or retrieve a session from
the session pool.
:rtype: :py:class:`pyqldb.session.qldb_session.QldbSession`
:return: A QldbSession object.
:raises ExecuteError: Error containing the context of a failure during start new session.
:raises SessionPoolEmptyError: If the timeout is reached while attempting to retrieve a session.
"""
logger.debug('Getting session. Current free session count: {}. Current available permit count: {}.'.format(
self._pool.qsize(), self._pool_permits_counter.value))
if self._pool_permits.acquire(timeout=self._timeout):
self._pool_permits_counter.decrement()
try:
if not start_new_session:
try:
session = self._pool.get_nowait()
logger.debug('Reusing session from pool. Session ID: {}.'.format(session.session_id))
return session
except Empty:
pass
logger.debug('Creating new session.')
return self._create_new_session()
except Exception as e:
self._pool_permits.release()
self._pool_permits_counter.increment()
raise ExecuteError(e, True, True)
else:
raise SessionPoolEmptyError(self._timeout)