From: "Rimon Barr" <barr@...>
> Hi Rien,
Hello Rimon !
thanks for having read my module. the idea came from my girlfriend who is a
web-designer. she had some troubles with a cgi counter, and I thought it
could be great to have one in spyce.
i marked it as useless, because it requires a lot more work to have it very
> - I changed the filename that you used from '/mydir/myfile.count' to
> '/mydir/counter.db', because shelve produces some rather big files, and
> there's no reason that they can not be shared. In fact, it may be
> advantageous to specify a single file for the entire system, though I
> don't think that we need to go that far.
i was using one file for each spyce script to avoid having some problems if
2 requests comes at the same time in the same directory.
> - I perform count.close() in the start method. If you wait until the
> finish(), then the counter will be left unupdated for the entire duration
> of the request processing. You might miss some hits this way. What I have
> now does not guaranteed to eliminate race conditions, but it's better than
> before. (Perhaps you want to implement some locks, but it's only a counter
that's right, i noticed it later.
> - It's easier to get the script filename from the spyce wrapper, ie.
> self.wrapper.getFilename(). I didn't expect you to know this, though,
> because none of the internal Spyce engine objects (including wrapper) are
i try to read some spyce code to know much more of the inside-spyce, but i
take me a lot of time, and this module was made in only a few minutes.
> - There is no reason to call the request module's uri() method numerous
> times. It's just expensive, and for no reason. I store the result in a
> local variable.
right too !
> - Python 1.5 does not support the += operator.
i wasn't knowing, i always code in 2.x. sorry...
> - You can use exception handling (as above) to save some disk access. i.e.
> You don't need to lookup the existence of a key using has_key() in the
> disk-based hashtable. Just try and deal with the exceptions.
good idea again, i do rarely use exception, though i should !
> - You don't need a get() method, when a field is sufficient. I changed the
> 'get()' method to a field called 'count'. This is more a matter of taste.
that's why it was in a get() method, only a matter of taste.
> I hope that helps; sorry for the delay. Nice work for the first person
> aside from me to write a Spyce module! I know that the documentation in
> this regard is sparse, and I was glad to see that you no trouble writing
i know that you are searching for more modules to get more features in
spyce. i'm trying to figure out what could be interesting for
since the time i send it, i tried my flavour of the module a bit more, and i
noticed a big problem:
when 2 request are coming at the same time for the same file, it can simply
crash apache. i hadn't much time to figure out why.
this lead me rewrite it a lot. i started but because of a lack of time, i
couldn't get it finished. my idea was to inspire me from the session module.
this would allow the user to choose where to store their counters, to have
different standard Handlers to choose from (one with one file per script in
the script dir, another with one file per script in a global dir, another
with one big file for the whole server, and a last one as you wrote it with
one file per dir), and to write their own counter handler to match their
needs. i had a hard time trying to read the code from the session module,
but i think i understood the basis. a more powerful version would be
implemented with a lock on the counter files to avoid having 2 request
accessing the same db at the same time (isn't it the purpose of the lock.py
if i find some other features that could have some interests for users, be
sure i will code it !