file open verification

Chris Liechti cliechti at gmx.net
Tue Oct 1 14:42:21 EDT 2002


cstrickland at surry.net (Charles W. Strickland) wrote in
news:3d99213c.521452 at nntp.surry.net: 

> On 27 Sep 2002 19:30:38 +0200, Chris Liechti <cliechti at gmx.net> wrote:
> 
>>python473 at yahoo.com (John Howard) wrote in 
>>news:9eabe547.0209270710.17ca112d at posting.google.com:
>>
>>> Two questions - somewhat related:
>>> 
>>> Situation - I have several files on an apache server that are being
>>> accessed by
>>> python programs that are receiving data from html forms.
>>> 
>>> q1: How can the status of a file be checked?  If two forms have been
>>> submitted
>>> and the data is being added to a common file, how do I know that
>>> data from both forms are being written correctly to the common file?
>>
>>don't ever write simultaneous from two processes to one file. your
>>choices are:
>>- use "locks", so that only writes at a time
>>- one server writes the file, logs are directed to that server (like
>>syslog  on linux)
> 
> Not sure what you mean here.  Are you saying that if a server file is
> used, then it is not a problem?

what's a server file? what i mean is that _somewhere_ there must be a lock 
than guarantees that one entry is written after an other. there are many 
solutions for that problem. one is that you use a server that writes the 
file. all client programs send their messages to that server.

or you can do locks on your own, in each of you client programs. when two 
programms run a the same time, they have to communicate somehow so that 
only one accesses a resource (e.g. you logfile) at a time. one easy 
solution is to use a lockfile. (that seems to be an example for lockfiles: 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203)

you can avoid lockfiles with a logging server (but somehow there is a lock 
involved) such a server can use a Queue (in python module with the same 
name) and one thread that writes the file and many threads that collect the 
data (e.g. from sockets) and put it in the Queue.

>  Is that related to his apache
> question?  Does the apache server handle locks?

i dont think that the server does this four your CGI programs. apache has 
such a logging server which is used to write access and error logs, but i 
don't think they are available to user CGIs.

chris

>>all these options ensure that one writes after the other. avoiding
>>problems is better than fixing.
>>
>>> q2: Related to above - really more of a cgi question - does the
>>> apache server keep all these file accesses separate some way?
>>
>>don't know apache. if you manage to limit it on one thread, only one
>>can access the file. but iin that case the performace of the server is
>>poooooor ;-)


-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list