you dont need to define locking if you use each transaction in only a  
single thread.    Below, you are acquiring a connection and a new  
transaction all locally defined within a function, so this code is  
threadsafe without the need for locks, provided the callable on the  
inside doesn't place the "c" object in some kind of global  
datastructure where other threads could get to it.


On Mar 6, 2009, at 12:22 PM, Antonio Beamud Montero wrote:

>
> Hi all:
> I'm using only sqlalchemy sql expression language, and in  
> documentation
> appears that transactions objects are not thread safe.. Need I to
> implement a decorator like this?
>
> def transactional(fn):
>     def transact(self, *args):
>         c = self.engine.connect()
>         lock.acquire()
>         try:
>             t = c.begin()
>             fn(self, c, *args)
>             t.commit()
>         except Exception, e:
>             t.rollback()
>             raise
>         finally:
>             c.close()
>             lock.release()
>     transact.__name__ = fn.__name__
>
> Can I use sessions without define object mappings, to use session  
> thread
> local model, etc?
>
> Thanks.
>
> >


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to