Cgi Counter

Dominic Mitchell dom at semantico.com
Tue Oct 16 10:05:37 EDT 2001


Paul Rubin <phr-n2001d at nightsong.com> writes:
> Nomad <nomad***@***freemail.absa.co.za> writes:
> 
> > On Fri, 12 Oct 2001 12:59:04 -0700 (PDT), Neal Irwin
> > ...> 
> > fileWrite = open('count.txt', 'w')
> > fileWrite.write(str(intHits))
> > fileWrite.close
> > ...
> > Pretty simple, but it works...
> 
> Um, what happens if two requests (coming from different processes in
> the web server) run the hit counter at the same time?  You need some
> kind of interlocking for this to be reliable.

Alternatively, if you don't mind losing the occaisional hit, you could
just write to a temp file and rename into place.  Renaming is an
atomic operation (under Unix, anwyay, dunno about win32), so you won't
get corruption, just a few lost hits.

-Dom

-- 
| Semantico: creators of major online resources          |
|       URL: http://www.semantico.com/                   |
|       Tel: +44 (1273) 722222                           |
|   Address: 33 Bond St., Brighton, Sussex, BN1 1RD, UK. |



More information about the Python-list mailing list