[Tutor] static variables - lock/semaphore
Kent Johnson
kent37 at tds.net
Sat Jul 1 16:30:56 CEST 2006
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
More information about the Tutor
mailing list