Wrap and intercept function calls

Dan Yamins dyamins at gmail.com
Thu Feb 18 01:09:06 CET 2010


> For CPython, alternative 1 is to create a custom interpreter to change
> (wrap) the interpretation of the call-function bytecode in the ceval loop.
> That is its 'call event', and I believe this would catch every explicit
> f(args) call and only such calls.
>
>


> Python has no general metasyntax for changing the semantics of its syntax.
> The __xx__ methods are special cases for the corresponding operators *and*
> the corresponding user-defined class. The '__call__' method of a class
> applies to instances of that class. Alternative 2:
>
>
Terry thanks for your response.

My hoped-for spec explicitly prohibits wrapping required each (user-defined)
function to be wrapped individual, since I want to be able to have this
wrapping behavior apply to many functions created by many users on the fly,
and such users can't be asked to remember to wrap each function.  (At most,
they can be asked to set a single evironment variable or the like at the
beginning of modules or interpreter sessions that should the "turn on
wrapping" for all future function calls.)

So I suppose the situation is as I feared? That the only way to achieve my
goal without having to wrap every (user-defined) function call individually
is to modify the interpreter.   Is there no way to edit frame objects from
inside a function?  if I could do that in a settrace function, would it even
help?

Also: am I right in thinking that the "modified interpreter" approach would
mean that my resulting software couldn't be used as a 3-rd party module,
that could be easily integrated into existing python installations?  Or is
there some standard way of integrating dynamically loadable modifications to
the interpreter in python?  (e.g. so that users of my code wouldn't have to
re-install of their existing modules in a separate new python installation?)

Thanks!
Dan




>
>>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100217/ae8e59b3/attachment.html>


More information about the Python-list mailing list