[Python-Dev] Hook Extension Module Import?

Guido van Rossum guido@python.org
Sun, 20 Apr 2003 17:20:03 -0400

> I think I need a way to temporarily (from 'C'), arrange to be notified
> just before and just after a new extension module is loaded.  Is this
> possible?  I didn't see anything obvious in the source.  BTW, I'd be
> just as happy if it were possible to do the same thing for any module
> (i.e., not discriminating between extension and pure python modules).

I think Aahz is slowly leading you in the right direction: you can
override __import__ with something that calls your pre-hook, then the
original __import__, then your post_hook.  I see no problem with doing
this from C except that it's a bit verbose.

--Guido van Rossum (home page: http://www.python.org/~guido/)