Code checksums at compile time?
gat at jpl.nasa.gov
Thu Jun 13 02:35:06 CEST 2002
I am running some code that computes results that are stored in a
database. The code is modified on occasion, and it's important to keep
track of which version of the code generated which results. It's
important enough to get this right that I want to do this automatically
and not risk the possibility of manual error.
I'm doing the following: the code in question lives in a module called
'foo'. When I load foo, I do the following:
code = 
hash = md5.new()
for line in xreadlines.xreadlines(open(foo.__file__)):
I then write the (hash,code) pair into the database, and annotate all the
results with the hash value. Now I have a foolproof record of which code
generated which results.
This works, but it's expensive, because this code is part of a cgi script,
so it has to recompute the hash every time it starts up.
My question is: is there a way to arrange for the module hash to be
computed at compile time rather than run time? This would seem to be a
straightforward adaptation of my current code, except that I don't know
how to get a handle on "the module that is currently being compiled" (and
its associated file).
More information about the Python-list