Python interceptor package

Dominic nomail at nospam.no
Wed Jun 16 04:51:31 EDT 2004


Fritz Bosch wrote:
> Hi group
> 
> I'm looking for a Python interceptor package, which will allow me to
> intercept the invocation of any function or method call.
> 
> For those familiar with CORBA interceptors, this should be roughly
> analogous (though simpler as we don't have a client and server side)
> but should work for any native Python invocation.
> 
> A trivial but practical use of such interceptors could be to log such
> invocations (also see the 'Interceptor pattern' from POSA2 by Douglas
> Schmidt, et. al.)
> 
> In particular
> - It should be possible to intercept
>   - Method calls (instance, class and static methods), either for
>     a specific instance or for all instances of a class (possibly
>     distinguishing between inherited and new or overridden methods)
>   - Function calls
>   - Calls to other callables
> - It should not require any modification to existing modules
>   in a system
> - It should be possible to install and remove such interceptors
>   at run-time (deriving a class and overriding a method is not
>   an option).
> - It should be possible to install multiple interceptors (serving
>   different purposes) for any function/method
> 
> Has any work been done in this direction?
You seem to look for:
import sys
sys.settrace(...)
(Python interpreter hook), it should do the job.

Ciao,
  Dominic


> Thanks
> Fritz



More information about the Python-list mailing list