dimanche 20 mars 2016

SQLAlchemy multithreading without flesk

I want to access a sqlite database file from the main thread and a background thread. The problem is no matter how i change my code i always get the following problem:

ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id -1250925472 and this is thread id -1225814016

my code looks something like that:

engine = create_engine('sqlite:///data/storage.sqlite', poolclass=NullPool)
Footprint.Base.metadata.create_all(engine)
session_factory = sessionmaker(bind=engine)
Session = scoped_session(session_factory)

def storeData(fp):
    s = Session()
    s.add(fp)
    s.commit()

Has anybody an idea how to fix this annoying problem?

Aucun commentaire:

Enregistrer un commentaire