Even that isn't so simple, because these need to vanish when the frame does
(you wouldn't want the dict to hold a reference to the frame!). Also, most
of the libraries that would be using this (cprofile, tracemalloc,
traceback, the new profiler I'm working on) are in C, so it wouldn't be a
straightforward monkeypatch. It would probably be easier to do a real
implementation than a demo.

What would the goal of an effective demo be?

On Wed, Jul 17, 2019 at 9:07 PM Andrew Barnert <[email protected]> wrote:

> On Jul 17, 2019, at 20:23, Andrew Barnert via Python-ideas <
> [email protected]> wrote:
>
> On Jul 17, 2019, at 18:41, Yonatan Zunger <[email protected]> wrote:
>
>
> I'm in the middle of developing a fancy heap profiler for Python (for
> those times when tracemalloc isn't enough), and in the process, thought of
> a small change in the interpreter which could have a lot of uses. I call it
> "scope painting" because it lets you paint a label on an interpreter scope.
>
> *Conceptual TL;DR: *Add a function which attaches a string label to the
> current interpreter frame. (This would go away when you either explicitly
> cleared it, or the frame ended, i.e. the current function returned)
>
>
> Can you get 90% of this by creating a global WeakKeyDictionary mapping
> frames to names, and monkey patching the relevant modules to use it? It
> might be too inefficient for some uses, but it seems like it should be good
> enough to demo the idea and show off some of the ways it could be used.
>
>
> Actually, it looks like frame objects can’t be weakref’d. So, I guess a
> regular dict, and a settrace function that removes the entry on return is
> probably the best way to do this in current Python? Still probably good
> enough for demo purposes.
>
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/FOTUBAFZ4BH5IVNB67ZWPTPJPUSUEWOI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to