如何深度复制Python的堆栈帧Obj

2024-05-23 23:23:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望在对python的调试器(PDB)进行更改时执行python堆栈框架的深层复制。在

curframe = self.get_stack(self.__f, self.__t)[0][self.curindex][0]
curframe_locals = copy.deepcopy(curframe.f_locals) # This line fails
# ERROR: *** TypeError: TypeError('object.__new__(NotImplementedType) is not safe, use NotImplementedType.__new__()',)
curframe_globals = curframe.f_globals

在哪里

^{pr2}$

但是根据复制库找到的:ftp://ftp.eso.org/scisoft/scisoft4/linux/redhat9/python/lib/python2.2/copy.py

This version does not copy types like module, class, function, method, nor stack trace, stack frame, nor file, socket, window, nor array, nor any similar types.

我的问题是,我运行的程序在执行代码之前对表达式求值,例如:

a = []
a.append(1) # This gets called twice, but I only want the affect to happen once.
# The program starts up a PDB instance and evaluates the lines execution and  
# maintains the results.

我仍然想确保我执行求值,但需要堆栈帧的深层副本,以便求值不会导致不需要的更改,有什么方法可以做到这一点?在

我正在考虑一个解决方案,我只执行进程,让它为我做深拷贝,尽管我不确定这是否可行,我需要将输出通过管道返回给父进程。在

谢谢!在


Tags: theselfnewstack堆栈notthispdb