-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing runtime state #26
Comments
pudb and pdb use literally the same code to implement user commands/variable assignments. It turns out that this is fine (and works in pudb and pdb) within the global scope, where variables are kept in a dict, but it very nearly can't be done inside a function, where variables are kept in the VM stack. If you know otherwise, please let me know. |
I see. It sounds like a hard problem. |
As of Python 3.6.6 this seems to be resolved in pdb, it can change local variables. |
Interesting. In that case, could you look into what |
@kgabor I can't reproduce this. I use this script to test, on Python 3.7.3rc1. def f():
i = 0
while i < 10:
i = i+1
print(i)
f() I use pdb to step into
which seems to contradict your statement. |
I think this should be re-opened as it works in pdb. When I test the code from #26 (comment), I can modify
This is on Python 3.10.8. |
It looks like pdb achieves this by making a copy of f_locals https://github.com/python/cpython/blob/aa8b58cb33826bd2b1a1de631ebcd6a5353eecb5/Lib/pdb.py#L299. Otherwise, frame.f_locals recomputes the locals every time it is accessed, wiping any changes that were made to it. |
This still requires more testing, especially for the different shells. For the IPython shell, this requires not making a copy of locals(), but this also causes the IPython shell to pollute the locals() namespace with all its internal variables (like _0 and so on), so a better fix is needed. Fixes inducer#26.
I have an in progress PR for a similar change for pudb to #571. It requires more testing, and also some cleaning up for the different shells. |
Why is it that when I assign variables in the shell, these assignments are not reflected in the running programme? When I use pdb, I am able to freely change the values of variables and execute the programme with my changes.
Is this ability omitted intentionally?
Is it possible to add?
The text was updated successfully, but these errors were encountered: