2

I have a class extending bdb.Bbd that I use for analyzing Python 3 code. Now, I need to also modify some of the variable values as it steps through the program.

Outside of functions, I can do this by just modifying the frame.f_locals dictionary:

frame.f_locals['x'] = 2

I can't figure out how to do this inside functions without using the ctypes trick mentioned in this question. I'm running Python 3 inside Pyodide which unfortunately does not support ctypes yet.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Kasra Ferdowsi
  • 574
  • 5
  • 16

1 Answers1

2

It should be possible to do this as follows. Define a Javascript function:

function frameLocalsToFast(frame){
   pyodide._module._PyFrame_LocalsToFast(frame.$$.ptr, 0);
   // Hopefully avoid memory leak
   frame.destroy();
}

Then import frameLocalsToFast into Python and call it when you want to update the frame.

Hood
  • 158
  • 1
  • 8