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/BZSLLB76OLJRYFCH55NUPYUHYNNWBKE3/ Code of Conduct: http://python.org/psf/codeofconduct/
