I dont know if it is related, but there is a Locking plugin

http://web2py.com/plugins/default/locking

On Thu, Jan 26, 2012 at 7:05 AM, Sebastian E. Ovide <
sebastianov...@gmail.com> wrote:

> ok, I guess that the answer is no... (or I didn't formulate the question
> correctly....)
>
>
> On Thu, Jan 19, 2012 at 11:51 PM, sebastian <sebastianov...@gmail.com>wrote:
>
>> Hi All,
>>
>> just thinking on how to implement a distributed locking system in web2py
>> using a DB: one row per each lock, lock_name is unique, if the row doesn't
>> exist, then it is locked, if the row exist already, then it cannot be lock
>> as it is already locked !
>>
>> I'd like to create a module like this (that can be called from anywhere
>> in web2py)
>>
>> def lock(lock name):
>>    begin transaction
>>    does the row exist ?
>>      no => insert new row
>>    commit transaction
>>    return result
>>
>> def unlock(lock_name):
>>    begin transaction
>>    delete row where name = lock_name
>>    commit transaction
>>
>>
>> BUT.... not sure if this is possible (of course it is !) in web2py...
>>
>> consider this controller
>>
>> def hello1():
>>    do a  lot of things
>>    db.commit()
>>    do more things in the DB
>>
>>    ### here is my doubt: #######################
>>    if lock("some resource"): ###  I'm calling a method that opens and
>> close a transaction inside a transaction !!!
>>       do something
>>       unlock("some resource")
>>    else
>>      do something else
>>
>>    #### another example ####################3
>>    if lock("resource A"):
>>      if lock("resource B"):
>>         do a lot of things woth both resources
>>         unlock("resource B")
>>         unlock("resource A")
>>      else
>>        so other things
>>        unlock("resource A")
>>
>>    do more things
>>
>>    db.commit()
>>    do more staff
>>
>>
>>  any better idea ?
>>
>> thansk
>>
>
>
>
> --
> Sebastian E. Ovide
>
>
>
>


-- 

Bruno Rocha
[http://rochacbruno.com.br]

Reply via email to