
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from nova import flags

FLAGS = flags.FLAGS

_ENGINE = None
_MAKER = None


def get_session(autocommit=True, expire_on_commit=False):
    """Helper method to grab session"""
    global _ENGINE
    global _MAKER
    if not _MAKER:
        if not _ENGINE:
            _ENGINE = create_engine(FLAGS.sql_connection, echo=False)
        _MAKER = (sessionmaker(bind=_ENGINE,
                                autocommit=autocommit,
                                expire_on_commit=expire_on_commit))
    session = _MAKER()
    return session


from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from nova import flags

FLAGS = flags.FLAGS

_ENGINE = None
_MAKER = None


def get_session(autocommit=True, expire_on_commit=False):
    """Helper method to grab session"""
    global _ENGINE
    global _MAKER
    if not _MAKER:
        if not _ENGINE:
            _ENGINE = create_engine(FLAGS.sql_connection, pool_recycle=3600, echo=False)
        _MAKER = (sessionmaker(bind=_ENGINE,
                                autocommit=autocommit,
                                expire_on_commit=expire_on_commit))
    session = _MAKER()
    return session

Add the pool_recycle setting to enable connection pooling features for the sql engine. The setting is hard-coded to 3600 seconds (one hour) per the recommendation provided on sqlalchemy's site
Add the pool_recycle setting to enable connection pooling features for the sql engine.  The setting is hard-coded to 3600 seconds (one hour) per the recommendation provided on sqlalchemy's site
  
  from sqlalchemy import create_engine
  from sqlalchemy.orm import sessionmaker
  
  from nova import flags
  
  FLAGS = flags.FLAGS
  
  _ENGINE = None
  _MAKER = None
  
  
  def get_session(autocommit=True, expire_on_commit=False):
      """Helper method to grab session"""
      global _ENGINE
      global _MAKER
      if not _MAKER:
          if not _ENGINE:
-             _ENGINE = create_engine(FLAGS.sql_connection, echo=False)
+             _ENGINE = create_engine(FLAGS.sql_connection, pool_recycle=3600, echo=False)
          _MAKER = (sessionmaker(bind=_ENGINE,
                                  autocommit=autocommit,
                                  expire_on_commit=expire_on_commit))
      session = _MAKER()
      return session
  
Add the pool_recycle setting to enable connection pooling features for the sql engine. The setting is hard-coded to 3600 seconds (one hour) per the recommendation provided on sqlalchemy's site
## Code Before:

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from nova import flags

FLAGS = flags.FLAGS

_ENGINE = None
_MAKER = None


def get_session(autocommit=True, expire_on_commit=False):
    """Helper method to grab session"""
    global _ENGINE
    global _MAKER
    if not _MAKER:
        if not _ENGINE:
            _ENGINE = create_engine(FLAGS.sql_connection, echo=False)
        _MAKER = (sessionmaker(bind=_ENGINE,
                                autocommit=autocommit,
                                expire_on_commit=expire_on_commit))
    session = _MAKER()
    return session

## Instruction:
Add the pool_recycle setting to enable connection pooling features for the sql engine. The setting is hard-coded to 3600 seconds (one hour) per the recommendation provided on sqlalchemy's site
## Code After:

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from nova import flags

FLAGS = flags.FLAGS

_ENGINE = None
_MAKER = None


def get_session(autocommit=True, expire_on_commit=False):
    """Helper method to grab session"""
    global _ENGINE
    global _MAKER
    if not _MAKER:
        if not _ENGINE:
            _ENGINE = create_engine(FLAGS.sql_connection, pool_recycle=3600, echo=False)
        _MAKER = (sessionmaker(bind=_ENGINE,
                                autocommit=autocommit,
                                expire_on_commit=expire_on_commit))
    session = _MAKER()
    return session
