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

The debugger calls f_locals on all frames #13972

Open
impact27 opened this issue Mar 13, 2023 · 2 comments
Open

The debugger calls f_locals on all frames #13972

impact27 opened this issue Mar 13, 2023 · 2 comments

Comments

@impact27
Copy link
Contributor

impact27 commented Mar 13, 2023

To reproduce, debug the following code line by line, pressing next on each line:

import pandas as pd
import plotly.express as px
import plotly.io as pio
pio.renderers.default='svg'  # this line required for plots to show in Spyder Plots panel

df = pd.DataFrame([
    dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28'),
    dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
    dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')
])

fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task")
fig.update_yaxes(autorange="reversed") # otherwise tasks are listed from the bottom up
fig.show()

This results in: AttributeError: 'NoneType' object has no attribute 'layout'

The problem is that the IPython debugger calls frame.f_locals on every step on every call. Calling frame.f_locals will reset the locals of the frame, and plotly does this:
https://github.com/plotly/plotly.py/blob/a4b9887bc7d5f5151b803221fa650291840d150e/packages/python/plotly/plotly/express/_chart_types.py#L424

The second issue is that looping on all frames on each python instruction is slow:
spyder-ide/spyder#20571

@ccordoba12
Copy link
Member

@mlucool, our solution was to disable the IPython debuggerskip functionality (see spyder-ide/spyder-kernels#458). That's not that useful by itself because users need to mark what frames they want to skip first.

@mlucool
Copy link

mlucool commented Apr 1, 2024

Thanks @ccordoba12. I deleted my comment in part because it turns out debuggerskip was not adding that much for that specific test (that is, it matters, but not as much as something I am yet to figure out)

Carreau added a commit that referenced this issue Apr 2, 2024
I'm not 100% sure this is correct as technically the value of
__debugger_skip__ could change in the current frame while we are
stepping into it, but that is likely super rare, and the slowdown
that this create is problematic.

There is still a small overhead for me, but this should make the
experience much better.

See spyder-ide/spyder-kernels#458,
#13972,
spyder-ide/spyder#20571,
#14382
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants