Re: Help: using msvcrt for file locking
by Richard van de Stadt other posts by this author
Aug 26 2001 9:10PM messages near this date
Re: bsddb for simple database [very basic]
|
bsddb for simple database [very basic]
Sheila King wrote:
[...]
>
> For CGI, I need file locking. The alternatives are (as I understand
> them):
>
> 1. Have a server running, which controls access to the files, thus
> ensuring that only one process can write to the files at a time.
[...]
I missed the start of this thread, but doesn't then this work for you:
def oneAtTheTime():
f = posixfile.open (someFilename, 'a')
f.lock ('w|')
f.write ('something') # or do something else that no other process may do at this time
f.lock ('u')
f.close()
I've been using this for over 5 years. It controls access to a particular
file for a system that collects submissions for conferences, where most
submissions have to be dealt with very close to the deadline. (Designed
in order to deals with multiple webform submissions, it also saved me a
couple of times when a fileserver broke down. The submissions where
simply blocked on the webserver until the fileserver came up again a
few days later :-)
Richard.
--
http://mail.python.org/mailman/listinfo/python-list
|