[Python-Dev] Hook Extension Module Import?

David Abrahams dave@boost-consulting.com
Mon, 21 Apr 2003 07:14:57 -0400


Guido van Rossum <guido@python.org> writes:

>> 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.

So I take it a doc patch is in order.  That section which claims it's
impossible is certainly misleading...

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com