0

I have come across this concept of 'execution frames' in python while trying to understand what the inspect.currentframe() function is actually doing. I only superficially understand what an execution frame is. Python docs say that it holds some administrative information for debugging purposes but doesn't really go into the details of what it is. I found this answer where the author tries to detail what a frame is internally but it looks suspiciously similar to the definition of a namespace in python - refer docs

Can anyone with the sufficient knowledge explain the inner workings of execution frames in detail? Why python uses them? How python uses them? Including some examples will really help. Thanks in advance.

braceletboy
  • 98
  • 2
  • 7
  • 1
    Look around the `inspect` docs some more. The table at the top in particular tells what attributes are inside. Other than that, you'll need to ask a specific question. – Alex Hall Feb 25 '19 at 16:20
  • @AlexHall Yeah, that helped. Conceptually/theoretically, what significance do these frames have. Why does python use them and how does it use them? – braceletboy Feb 25 '19 at 16:27
  • 1
    In a nut shell, an execution frame is how Python tracks the values of local variables during a function call. Having to create and keep them in memory is what makes deep recursion a problem. – chepner Feb 25 '19 at 16:30
  • @chepner, isn't that the same as namespace - refer (https://docs.python.org/3/tutorial/classes.html#python-scopes-and-namespaces) Why have this? – braceletboy Feb 25 '19 at 16:33
  • 1
    A namespace is an important component of an execution frame. The execution frame also tells you where to go back *to* after the function call is complete. – chepner Feb 25 '19 at 16:42
  • Most languages, young and old, have a concept of frames. They contain all the information about what the program is currently doing and let the computer know what to do next. – Alex Hall Feb 25 '19 at 16:56

0 Answers0