ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved