Probably I'm missing something about SQLAlchemy used in threading
environment, but I can't make this code work whatever I do:
import sqlalchemy as sa
import random
db = sa.create_engine('postgres://alef:[EMAIL PROTECTED]:5432/test')
metadata = sa.BoundMetaData(db)
session = sa.create_session(bind_to=db)
customer_table = sa.Table('customer', metadata,
sa.Column('customerid', sa.Integer, primary_key=True),
sa.Column('name', sa.String()),
sa.Column('age', sa.Integer))
class Customer(object):
pass
Customer._mapper = sa.mapper(Customer, customer_table)
Customer.objects = session.query(Customer)
def worker():
c = Customer()
c.name = str(random.randint(0, 100))
c.age = random.randint(0, 100)
session.save(c)
session.flush()
c = Customer.objects.select_by(name=str(random.randint(0, 100)),
age=random.randint(0, 100))
print c
if __name__ == '__main__':
while True:
t = threading.Thread(target=worker)
t.setDaemon(1)
t.start()
I tried adding threadlocks, using threadlocal, but whatever I use, I get
some kind of exception...
Thanks in advance.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users