On Apr 25, 2013, at 2:59 PM, sajuptpm <[email protected]> wrote:
> Hi,
>
> I have a locking system like this
>
> class LockManager:
> def get_lock(self, id):
> lock_m=DBSession.query(Locker).with_lockmode("update").\
> filter(Locker.id==id).all()
> if len(lock_m) == 0:
> lm=Locker(id)
> DBSession.add(lm)
>
> def release_lock(self):
> transaction.commit()
>
> Issues
> =======
>
> 1) I can't use this in nested form, since release of inner transaction will
> release outer transaction also, since release using transaction.commit()
>
> Example:
> --------
> ##Outer lock start
> LockManager.get_lock("1")
> //Do something
> ##Inner lock start
> LockManager.get_lock("2")
> //Do something
> ##Inner lock release(Issue:This will release outer lock also)
> LockManager.release_lock()
> ##Outer lock release
> LockManager.release_lock()
>
>
> How to solve this issue ???
I can't speak for "transaction" specifically, assuming that is the zope
transaction extension. I'm not sure that it supports nesting of transactions
and you'd need to ask on the Pyramid list.
You can get arbitrary nesting using SQLAlchemy APIs directly - since you are
looking for ad-hoc transactions you'd run the Session starting with
autocommit=True:
def do_something(session):
session.begin(subtransactions=True)
do_something(session)
session.commit()
session = Session(autocommit=True)
do_something(session)
calling session.begin(subtransactions=True) allows for nesting of begin/commit
calls - only the outermost begin/commit actually controls the transaction.
I'd make sure that the Session is not used outside of begin()/commit(), it will
autocommit operations outside.
>
> Thanks,
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.