wrapping all class methods

Bengt Richter bokr at oz.net
Sun Nov 17 07:57:55 EST 2002


On Sun, 17 Nov 2002 10:56:39 +0000, Robin Becker <robin at jessikat.fsnet.co.uk> wrote:

>In article <ar6jkk$17g$0 at 216.39.172.122>, Bengt Richter <bokr at oz.net>
>writes
>......
>>>..... no I hadn't used that, but then I don't want a trace I want to
>>>discover which tracebacks are being detected and trapped.
>>
>>I thought you might be able to do a silent trace and see the exceptions
>>before they're "trapped". (The hook doesn't do any output or force you to.
>>You choose what to do if/when you see something of interest).
>>
>
>this is probably a good way to go as it is non-invasive, but it's a new
>technology for me so I'd need to wrap my decreasing neurones around it
>before use.
>
>The wrapping approach applies itself to all classes and all method
>members, but in my example I see base class methods are also being
>wrapped which may or may not be desired.
>
>I suppose a global tracefunc could check at each 'call' whether the
>currently entered scope is wanted and then set a local trace.
>
Yes. Which also implies that you need a dictionary of interesting scopes
to check, or some I-don't-know-what other fast way of checking.

>I wonder how fast this is compared to the wrapping approach.
>
Probably slow. I typed help(i_forgot_what) with tracewatch on, and it
sure slowed that down quite noticeably. I guess every function/method call
is becoming two at least, so even if my scope-of-interest check is fast and
says no, there's still the call overhead all over the place.

So if you have real time considerations at all, it's probably too slow.

I don't want to lead you down the garden path. I have just done enough
to get the result you saw plus being able to monitor name bindings in
scopes of interest. But the docs I found were sparse, so I'm not sure
how solid a ground I've built on. IOW, I'm not sure **exactly** how what I
did is working. I haven't gotten back to digging. I guess I won't feel like
I have a grip until I've looked at the code that implements the hook calls.

Anyway, I just wanted to offer detour route to consider if you got stuck.
If you're not stuck, drive on ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list