Hi all,
I'm trying to share an object with a thread, I already tryed to use
Session.merge but I'm doing something wrong,
here is a test case:
from sqlalchemy import
*
from sqlalchemy.orm import
*
e = create_engine('postgres://postgres:[email protected]/test',
echo=True)
m = MetaData(e)
t1 = Table('t1', m, Column('a', Integer, primary_key=True),
Column('b', Integer))
class A(object):
def __init__(self, a, b):
self.a = a
self.b = b
mapper(A, t1)
m.create_all()
Session = scoped_session(sessionmaker())
Session.add(A(1, 1))
Session.commit()
import threading
def testthread(a):
a.a=2
Session.add(a)
Session.commit()
a = Session.query(A).get(1)
t=threading.Thread(target=testthread,args=(a,))
t.start()
and this is the generated expection:
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 525, in
__bootstrap_inner
self.run()
File "/usr/lib/python2.6/threading.py", line 477, in run
self.__target(*self.__args, **self.__kwargs)
File "testthread.py", line 28, in testthread
Session.add(a)
.....
InvalidRequestError: Object '<A at 0x2dbf390>' is already attached to
session '47955344' (this is '47969872')
what is the correct way to share object between different threads?
regards
drakkan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---