How to inspect a variable (sys.modules) for changes in the execution of a program?

Chris Rebert clp2 at rebertia.com
Tue Feb 15 19:19:07 CET 2011


On Tue, Feb 15, 2011 at 7:17 AM, Jorge Vargas <jorge.vargas at gmail.com> wrote:
> Hello,
>
> I have the following situation. In a big project that involves many
> dependencies (and sadly some sys.module hacks) we have a bug, and it
> will really help if i could monitor all changes made to that variable.
> Is there a way to trace those changes ?

Is the variable's value of a mutable or immutable type? What is the
variable's scope (e.g. module-level global, or object attribute)? Is
the variable subject to getting rebound to an entirely new
value/object?

The answers to these questions will determine how much work will be
required to trace "changes" to the variable. I know of no built-in way
to directly do such a thing, but the underlying functionality
necessary to implement such a feature (e.g. sys.settrace,
__getattribute__, __setattr__) does exist.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list