def create_engine(sql_connection):
 connection_dict = sqlalchemy.engine.url.make_url(sql_connection)
 engine_args = {'pool_recycle': CONF.sql_idle_timeout, 'echo': False, 'convert_unicode': True}
 if (CONF.sql_connection_debug >= 100):
  engine_args['echo'] = 'debug'
 elif (CONF.sql_connection_debug >= 50):
  engine_args['echo'] = True
 if ('sqlite' in connection_dict.drivername):
  engine_args['poolclass'] = NullPool
  if (CONF.sql_connection == 'sqlite://'):
   engine_args['poolclass'] = StaticPool
   engine_args['connect_args'] = {'check_same_thread': False}
 else:
  engine_args['pool_size'] = CONF.sql_max_pool_size
  if (CONF.sql_max_overflow is not None):
   engine_args['max_overflow'] = CONF.sql_max_overflow
 engine = sqlalchemy.create_engine(sql_connection, **engine_args)
 sqlalchemy.event.listen(engine, 'checkin', greenthread_yield)
 if ('mysql' in connection_dict.drivername):
  sqlalchemy.event.listen(engine, 'checkout', ping_listener)
 elif ('sqlite' in connection_dict.drivername):
  if (not CONF.sqlite_synchronous):
   sqlalchemy.event.listen(engine, 'connect', synchronous_switch_listener)
  sqlalchemy.event.listen(engine, 'connect', add_regexp_listener)
 if (CONF.sql_connection_trace and (engine.dialect.dbapi.__name__ == 'MySQLdb')):
  patch_mysqldb_with_stacktrace_comments()
 try:
  engine.connect()
 except sqla_exc.OperationalError as e:
  if (not is_db_connection_error(e.args[0])):
   raise
  remaining = CONF.sql_max_retries
  if (remaining == (-1)):
   remaining = 'infinite'
  while True:
   msg = _('SQL connection failed. %s attempts left.')
   LOG.warn((msg % remaining))
   if (remaining != 'infinite'):
    remaining -= 1
   time.sleep(CONF.sql_retry_interval)
   try:
    engine.connect()
    break
   except sqla_exc.OperationalError as e:
    if (((remaining != 'infinite') and (remaining == 0)) or (not is_db_connection_error(e.args[0]))):
     raise
 return engine

def create_engine ( sql_connection ) : connection_dict = sqlalchemy . engine . url . make_url ( sql_connection ) engine_args = { 'pool_recycle' : CONF . sql_idle_timeout , 'echo' : False , 'convert_unicode' : True } if ( CONF . sql_connection_debug >= 100 ) : engine_args [ 'echo' ] = 'debug' elif ( CONF . sql_connection_debug >= 50 ) : engine_args [ 'echo' ] = True if ( 'sqlite' in connection_dict . drivername ) : engine_args [ 'poolclass' ] = NullPool if ( CONF . sql_connection == 'sqlite://' ) : engine_args [ 'poolclass' ] = StaticPool engine_args [ 'connect_args' ] = { 'check_same_thread' : False } else : engine_args [ 'pool_size' ] = CONF . sql_max_pool_size if ( CONF . sql_max_overflow is not None ) : engine_args [ 'max_overflow' ] = CONF . sql_max_overflow engine = sqlalchemy . create_engine ( sql_connection , ** engine_args ) sqlalchemy . event . listen ( engine , 'checkin' , greenthread_yield ) if ( 'mysql' in connection_dict . drivername ) : sqlalchemy . event . listen ( engine , 'checkout' , ping_listener ) elif ( 'sqlite' in connection_dict . drivername ) : if ( not CONF . sqlite_synchronous ) : sqlalchemy . event . listen ( engine , 'connect' , synchronous_switch_listener ) sqlalchemy . event . listen ( engine , 'connect' , add_regexp_listener ) if ( CONF . sql_connection_trace and ( engine . dialect . dbapi . __name__ == 'MySQLdb' ) ) : patch_mysqldb_with_stacktrace_comments ( ) try : engine . connect ( ) except sqla_exc . OperationalError as e : if ( not is_db_connection_error ( e . args [ 0 ] ) ) : raise remaining = CONF . sql_max_retries if ( remaining == ( - 1 ) ) : remaining = 'infinite' while True : msg = _ ( 'SQL connection failed. %s attempts left.' ) LOG . warn ( ( msg % remaining ) ) if ( remaining != 'infinite' ) : remaining -= 1 time . sleep ( CONF . sql_retry_interval ) try : engine . connect ( ) break except sqla_exc . OperationalError as e : if ( ( ( remaining != 'infinite' ) and ( remaining == 0 ) ) or ( not is_db_connection_error ( e . args [ 0 ] ) ) ) : raise return engine
create a new :class: .