1

I'm looking to perform a deep copy of python's stack frame as I'm making changes to Python's debugger (PDB).

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

Where

__f = <frame object at 0x10185fad0>
__t = None

But according to the copy library and found here: 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.

My problem is that the program I run evaluates expressions before executing the code, such as:

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.

I still want to make sure I do the evaluation, but need a deep copy of the stack frame so that the evaluation doesn't cause unwanted changes, any way that I can do this?

I'm considering a solution where I merely exec the process and have it do the deep copy for me, though I'm not sure if this would work and I'd need to pipe the output back to the parent.

Thanks!

nnegrey
  • 66
  • 5

0 Answers0