반응형
I. import 모듈
import eventlet.patcher
eventlet.patcher.monkey_patch()
import eventlet.db_pool
import sqlalchemy.orm
import sqlalchemy.pool
try:
import MySQLdb
except ImportError:
MySQLdb = None
eventlet.patcher.monkey_patch()
import eventlet.db_pool
import sqlalchemy.orm
import sqlalchemy.pool
try:
import MySQLdb
except ImportError:
MySQLdb = None
II. orm sessionmaker 함수를 통한 session 생성
session = sqlalchemy.orm.sessionmaker(bind=engine,
autocommit=autocommit,
expire_on_commit=expire_on_commit)
autocommit=autocommit,
expire_on_commit=expire_on_commit)
III. sessionmaker의 첫번째 인수, bind 를 하기 위한 engine 을 생성하는 방법
engine = sqlalchemy.create_engine(FLAGS.sql_connection, **engine_args)
IV. create_engine을 하기 위한 engine_args dict 변수를 만드는 방법
engine_args = {
"pool_recycle": FLAGS.sql_idle_timeout,
"echo": False,
}
engine_args["pool_size"] = FLAGS.sql_max_pool_size
engine_args["pool_timeout"] = FLAGS.sql_pool_timeout
engine_args["creator"] = creator.create
"pool_recycle": FLAGS.sql_idle_timeout,
"echo": False,
}
engine_args["pool_size"] = FLAGS.sql_max_pool_size
engine_args["pool_timeout"] = FLAGS.sql_pool_timeout
engine_args["creator"] = creator.create
V. creator (Connection Pool) 를 구하는 방법
creator = eventlet.db_pool.ConnectionPool(MySQLdb, **pool_args)
VI. ConnectionPool을 구하기 위한 pool_args 변수를 만드는 방법
# sqlalchemy.engine.url.make_url 을 이용하면 url 을 가지고 dict 형태로 변환이 가능하다.
connection_dict = sqlalchemy.engine.url.make_url(FLAGS.sql_connection)
pool_args = {
"db": connection_dict.database,
"passwd": password,
"host": connection_dict.host,
"user": connection_dict.username,
"min_size": FLAGS.sql_min_pool_size,
"max_size": FLAGS.sql_max_pool_size,
"max_idle": FLAGS.sql_idle_timeout,
}
connection_dict = sqlalchemy.engine.url.make_url(FLAGS.sql_connection)
pool_args = {
"db": connection_dict.database,
"passwd": password,
"host": connection_dict.host,
"user": connection_dict.username,
"min_size": FLAGS.sql_min_pool_size,
"max_size": FLAGS.sql_max_pool_size,
"max_idle": FLAGS.sql_idle_timeout,
}
반응형