Skip to content
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

%debug magic does not work repeatably for untitled files #16417

Closed
madphysicist opened this issue Sep 13, 2021 · 9 comments · Fixed by spyder-ide/spyder-kernels#369
Closed

%debug magic does not work repeatably for untitled files #16417

madphysicist opened this issue Sep 13, 2021 · 9 comments · Fixed by spyder-ide/spyder-kernels#369

Comments

@madphysicist
Copy link

madphysicist commented Sep 13, 2021

What steps reproduce the problem?

  1. Create a simple file with a single cell with like this:

    #%% define foo
    def foo(bar):
        x = ['a']
        for i in range(100):
            x.append(i + 3)
        return x
    
  2. Execute the file using the green arrow:

    runfile('.../test.py', wdir='...')
    
  3. Place a breakpoint in line 4:
    image

  4. Run a %debug magic on foo with any argument:
    image

    Enters debugging normally:
    image

  5. Quit debugging (or step through) and try again

    image
    image

    Only "s" appears to work, and pressing "c" ignores the breakpoint entirely:

    image

Expected Behavior

I expect %debug to work twice, especially when I don't modify the file.

Attempted solutions:

  1. Rerun the file:
    image
    Does not work
  2. Modify the file, save it, then rerurn and attempt to debug. Output shows that the modification propagated to the foo in the console:
    image
    image
    Does not work.
  3. Clear all variables. Does not work.
  4. Restart kernel (or IDE). That works as expected every time. But doesn't seem like that's a very good solution.

Comment

The reason that I mention cells in the example is that ideally, I would like to reload my code by running the cell rather than the entire file. The files I have at the moment are sort of like notebooks that I am using the cell functionality to run. I would love not to have to reload the entire file (mush less the kernel), every time I made a change just to the function I'm trying to debug.

Versions

  • Spyder version: 4.1.5
  • Python version: 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)]
  • Qt version: 5.9.7
  • PyQt version: 5.9.2
  • Operating System name/version: Windows 10

Dependencies

# Mandatory:
atomicwrites >=1.2.0           :  1.4.0 (OK)
chardet >=2.0.0                :  4.0.0 (OK)
cloudpickle >=0.5.0            :  1.6.0 (OK)
diff_match_patch >=20181111    :  20200713 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.22.0 (OK)
jedi =0.17.1                   :  0.17.1 (OK)
nbconvert >=4.0                :  6.0.7 (OK)
numpydoc >=0.6.0               :  1.1.0 (OK)
paramiko >=2.4.0               :  2.7.2 (OK)
parso =0.7.0                   :  0.7.0 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.8.0 (OK)
pygments >=2.0                 :  2.8.1 (OK)
pylint >=1.0                   :  2.7.4 (OK)
pyls >=0.34.0;<1.0.0           :  0.34.1 (OK)
qdarkstyle >=2.8               :  3.0.2 (OK)
qtawesome >=0.5.7              :  1.0.2 (OK)
qtconsole >=4.6.0              :  5.0.3 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.7 (OK)
sphinx >=0.6.6                 :  3.1.2 (OK)
spyder_kernels >=1.9.4;<1.10.0 :  1.9.4 (OK)
watchdog                       :  None (OK)
zmq >=17                       :  20.0.0 (OK)

# Optional:
cython >=0.21                  :  0.29.23 (OK)
matplotlib >=2.0.0             :  3.3.4 (OK)
numpy >=1.7                    :  1.20.1 (OK)
pandas >=0.13.1                :  1.2.4 (OK)
scipy >=0.17.0                 :  1.6.2 (OK)
sympy >=0.7.3                  :  1.8 (OK)
@steff456
Copy link
Member

Hi @madphysicist,

Thanks for reporting, I was able to reproduce this issue. @impact27, do you know why this is happening?

@madphysicist
Copy link
Author

@steff456 Thanks for confirming. I always have a lingering doubt that I missed something stupid in the docs or configuration when I post bug reports.

@impact27
Copy link
Contributor

It looks like the breakpoints are broken for unsaved files. Can you reproduced for a saved file?

@madphysicist
Copy link
Author

madphysicist commented Sep 15, 2021

@impact27 the file was saved in this example. I used the name untitled0.py out of laziness, but it was on disk in my documents folder as indicated in the output.

I initially started posting the issue because the file wouldn't debug after I modified the function, saved, and reran the cell. But it quickly became apparent that there was no need to do all that. The debugging inline magic breaks even with a completely intact source.

@impact27
Copy link
Contributor

I can't reproduce with the latest 5.x

@impact27
Copy link
Contributor

To solve this for unsaved files, we could remove the last two lines of https://github.com/spyder-ide/spyder-kernels/blob/master/spyder_kernels/customize/namespace_manager.py , but that would mean the files stay cached forever

@ccordoba12 ccordoba12 added this to the v5.3.0 milestone Jan 15, 2022
@ccordoba12 ccordoba12 changed the title %debug magic does not work repeatably %debug magic does not work repeatably for untitled files Jan 15, 2022
@madphysicist
Copy link
Author

@ccordoba12 Thank you!

@ccordoba12
Copy link
Member

ccordoba12 commented Jan 25, 2022

@impact27 was the one who really fixed this.

@madphysicist
Copy link
Author

@impact27 thank you for the fix. I look forward to using it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants