I'm getting the error "sqlalchemy.exc.ProgrammingError: (ProgrammingError) 
SQLite objects created in a thread can only be used in that same thread.The 
object was created in thread id 5808 and this is thread id 7936 None None"

with my current setup, I'm not sure what I've done wrong.

I set up this little test to see if I could write to the same table from 
multiple threads. the table has 3 columns all of type int.


from sqlalchemy import create_engine, MetaData
from sqlalchemy.orm import scoped_session,sessionmaker
from sqlalchemy.ext.declarative import declarative_base

db_engine= create_engine("sqlite:///database.db"),echo=True)
Base= declarative_base(db_engine)

class Failures(Base):
  __tablename__= "failures"
  __table_args__= {"autoload":True}
  
  def __repr__(self):
    return "<Failures('%s','%s','%s')>" %(self.Id,self.action,self.reason)

metadata= Base.metadata
Session= scoped_session(sessionmaker(bind=db_engine))

class TestWriteToDB(threading.Thread):
  
  def __init__(self,start):
    threading.Thread.__init__(self)
    self.session= Session()
    self.insert_list=[]
    for i in range(start,start+10):
      f=Failures(resourceId=i,action=i,reason=i)
      self.insert_list.append(f)
      
  def run(self):
    self.session.add_all(self.insert_list)
    self.session.commit()
    

if __name__ == "__main__":
  for i in range(1,40,10):
    t=TestWriteToDB(i)
    t.start()
  





-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to