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