Ignore:
Timestamp:
9 Jul 2013, 07:16:32 (11 years ago)
Author:
uli
Message:

Make sure memory-based database is thread-oriented (all connections should share the same memory-DB).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.cas/trunk/waeup/cas/db.py

    r10406 r10419  
    66from sqlalchemy.ext.declarative import declarative_base
    77from sqlalchemy.orm import sessionmaker, scoped_session
     8from sqlalchemy.pool import StaticPool
    89
    910
     
    8182
    8283    def __init__(self, connection_string):
    83         self.engine = create_engine(connection_string)
     84        args = {}
     85        if connection_string in ('sqlite:///', 'sqlite:///:memory:'):
     86            # make sure all threads access the same memory
     87            args = dict(connect_args={'check_same_thread': False},
     88                        poolclass=StaticPool)
     89        self.engine = create_engine(connection_string, **args)
    8490        self.metadata = MetaData()
    8591        Base.metadata.create_all(self.engine)
Note: See TracChangeset for help on using the changeset viewer.