Re: [Tutor] static variables - lock/semaphore
if we compare rowlevel locking and global variables which scales and is better Alan Gauld [EMAIL PROTECTED] wrote: is there a way to use some sort of semaphore or lock so that it is not accessed simultaneously There are ways of doing this in Python but if you are using a relational database for the data its usually easier to apply row level locking at the database level. Row level locking in the database is far more scaleable than global variables. They are more reliable, only apply during the actual database writes and cannot be circiumvented by programs forking or spawning clones of themselves or by other applications accessing the same data. Almost all very high volume applicatoons use database locking - everything from banking systems to airtline bookings etc. Coupled to the transaction management features of a database (Commit, rollback etc) you can build very powerful, very scaleable databases capable of handling 100s of transactions per second. Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] static variables - lock/semaphore
hi i have a program that is run on a website, and as it is run from a website, it can be called more than once and hence could end up corrupting db/data is there a way to use some sort of semaphore or lock so that it is not accessed simultaneously the problem is it can be done with static variables in C but how is it done in python thanks a lot __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] static variables - lock/semaphore
i have a program that is run on a website, and as it is run from a website, it can be called more than once and hence could end up corrupting db/data is there a way to use some sort of semaphore or lock so that it is not accessed simultaneously There are ways of doing this in Python but if you are using a relational database for the data its usually easier to apply row level locking at the database level. the problem is it can be done with static variables in C but how is it done in python It could be done with a global variable in Python in the same way but there are other solutions based around threads which have explicit locks etc. For a web application using Python threads would probably be a good bet. But you may find the whole problem simplified by adopting a web framework such as TurboGears which will take care of a lot of these kinds of issues for you - but with a bit of a learning curve. But if you have several web apps to build I'd seriously consider this route. Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] static variables - lock/semaphore
anil maran wrote: hi i have a program that is run on a website, and as it is run from a website, it can be called more than once and hence could end up corrupting db/data is there a way to use some sort of semaphore or lock so that it is not accessed simultaneously the problem is it can be done with static variables in C but how is it done in python If you are using a database for storage you should learn how to use the transactional features of the database. They are designed to let you control what happens when multiple users access the database at the same time. To protect access to other kinds of data look at threading.Lock and RLock. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor