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

Use draw_idle instead of draw in remake_ticks #25

Merged
merged 1 commit into from
Aug 3, 2022

Conversation

jzuhone
Copy link
Contributor

@jzuhone jzuhone commented Jul 15, 2022

Description

xija_gui_fit is prone to crashing, often without error messages, or only cryptic error messages such as this one:

(ska) acis-110: xija_gui_fit ./dpa_spec_PROD.json --days 365 --stop 2022:105:00:00:00.00 &
Fetching msid: 1dpamzt over 2021:104:23:37:10.816 to 2022:105:00:19:02.816
info:numexpr.utils:NumExpr defaulting to 4 threads.
Fetching msid: sim_z over 2021:104:23:37:10.816 to 2022:105:00:19:02.816
Fetching msid: pitch over 2021:104:23:37:10.816 to 2022:105:00:19:02.816
Fetching msid: roll over 2021:104:23:37:10.816 to 2022:105:00:19:02.816
Fetching msid: aoeclips over 2021:104:23:37:10.816 to 2022:105:00:19:02.816
Getting kadi commanded states over 2021:105:00:04:30.816 to 2022:104:23:51:42.816
Fetching msid: dp_dpa_power over 2021:104:23:37:10.816 to 2022:105:00:19:02.816
Adding plot  1dpamzt data__time
Adding plot  1dpamzt resid__time
Traceback (most recent call last):
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 3031, in _wait_cursor_for_draw_cm
    yield
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py", line 439, in draw
    super().draw()
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/backends/backend_qt.py", line 424, in draw
    self.update()
RuntimeError: wrapped C/C++ object of type MplCanvas has been deleted

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 287, in process
    func(*args, **kwargs)
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/Ska/Matplotlib/core.py", line 97, in remake_ticks
    ax.figure.canvas.draw()
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py", line 439, in draw
    super().draw()
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 3033, in _wait_cursor_for_draw_cm
    self.canvas.set_cursor(self._lastCursor)
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/backends/backend_qt.py", line 259, in set_cursor
    self.setCursor(_api.check_getitem(cursord, cursor=cursor))
RuntimeError: wrapped C/C++ object of type MplCanvas has been deleted
Traceback (most recent call last):
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 287, in process
    func(*args, **kwargs)
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 3077, in _zoom_pan_handler
    self.release_zoom(event)
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 3232, in release_zoom
    self.push_current()
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 3243, in push_current
    self.set_history_buttons()
  File "/data/acis/miniconda3/envs/ska/lib/python3.8/site-packages/matplotlib/backends/backend_qt.py", line 797, in set_history_buttons
    self._actions['back'].setEnabled(can_backward)
RuntimeError: wrapped C/C++ object of type QAction has been deleted

This can be resolved if the call to ax.figure.canvas.draw is changed to ax.figure.canvas.draw_idle in remake_ticks, which is what this PR does.

From the Matplotlib documentation:

"In almost all cases, we recommend using backend_bases.FigureCanvasBase.draw_idle over backend_bases.FigureCanvasBase.draw. draw forces a rendering of the figure whereas draw_idle schedules a rendering the next time the GUI window is going to re-paint the screen."

Testing

  • Changing this line fixes crashes in xija_gui_fit.
  • I checked that the iplot functionality in cheta works correctly with this change.

@taldcroft
Copy link
Member

@jzuhone - thanks, looks reasonable. This probably also needs some testing of the original standalone functionality when running interactively in an IPython terminal session.

@jzuhone
Copy link
Contributor Author

jzuhone commented Jul 15, 2022

@taldcroft good call--I did check and the interactive plotting does work correctly.

@jzuhone
Copy link
Contributor Author

jzuhone commented Aug 3, 2022

any reason not to merge this PR?

@taldcroft taldcroft merged commit 4a9f1b5 into sot:master Aug 3, 2022
This was referenced Oct 5, 2022
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

Successfully merging this pull request may close these issues.

2 participants