Help with gdbm and fcntl.flock
Wayne Ringling
wayne at tbnets.com
Sun Oct 21 18:20:19 EDT 2001
I am trying to flock a gbdm file but I can't get it to work. Any ideas
really appreciated :)
I ripped out all the other stuff to just get this part working. It's a
small script to handle ip addrs for a smallish database. But I want to get
an exclusive lock on the database while I have it open for reading/writing
to. I have two little projects that I need this for if we can get it to
work. Is it possible to get a flock on a database object?
Here's a snippet from my code:
#!/usr/bin/python
#
import gdbm
import fcntl
def lock(file):
fcntl.flock(file, fcntl.LOCK_EX)
def main():
# Open database
try:
dbase = gdbm.open("remote_addr.dbm","w",0644)
except:
dbase = gdbm.open("remote_addr.dbm","c",0644)
# Now get exclusive flock
lock(dbase)
if __name__ == '__main__':
main()
Also I am using Python 2.0 if that makes any diference.
Wayne
More information about the Python-list
mailing list