def clear_locals(self):
    self._locals = {}

@property
def locals(self):
    return self._locals

@persistent_locals
def func():
    local1 = 1
local2 = 2
func()
print(func.locals)
Python: Is there a way to get a local function variable from within a decorator that wraps it?