from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker


session = None


def init_session(connection_string=None, drop=False):
    if connection_string is None:
        connection_string = 'sqlite://'

    from database.model import Base

    global session

    if drop:
        try:
            old_session = session
            Base.metadata.drop_all(bind=old_session.bind)
        except:
            pass

    engine = create_engine(connection_string, echo=True)
    db_session = scoped_session(sessionmaker(autocommit=False,
                                             autoflush=False,
                                             bind=engine))
    Base.metadata.create_all(bind=engine)

    session = db_session


@@ -86,16 +86,55 @@
 onmaker%0A
+from sqlalchemy.pool import StaticPool%0A
 %0A%0Asessio
@@ -244,39 +244,275 @@
     
-connection_string = 'sqlite://'
+engine =  create_engine('sqlite://',%0A                                echo=True,%0A                                connect_args=%7B'check_same_thread':False%7D,%0A                                poolclass=StaticPool)%0A    else:%0A        engine = create_engine(connection_string)
 %0A%0A  
@@ -722,65 +722,8 @@
 ss%0A%0A
-    engine = create_engine(connection_string, echo=True)%0A
     

Fix the database session init to work with the flask debug server.