Code checksums at compile time?
Erann Gat
gat at jpl.nasa.gov
Wed Jun 12 20:35:06 EDT 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:
import foo
code = []
hash = md5.new()
for line in xreadlines.xreadlines(open(foo.__file__)):
hash.update(line)
code.append(line)
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).
Thanks,
Erann Gat
More information about the Python-list
mailing list