Skip to content

Commit 5a6ae81

Browse files
committed
MNT: project Qt backends from recursive draws
This does not prevent the recursion, which may segfault Qt, but prevents it from infinitely recursing if Qt does not crash. Closes #9406
1 parent d073f1c commit 5a6ae81

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/matplotlib/backends/backend_qt5agg.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,22 @@ def draw_idle(self):
140140
QtCore.QTimer.singleShot(0, self.__draw_idle_agg)
141141

142142
def __draw_idle_agg(self, *args):
143+
# if nothing to do, bail
143144
if not self._agg_draw_pending:
144145
return
146+
# we have now tried this function at least once, do not run
147+
# again until re-armed. Doing this here rather than after
148+
# protects against recursive calls triggered through self.draw
149+
self._agg_draw_pending = False
150+
# if negative size, bail
145151
if self.height() < 0 or self.width() < 0:
146-
self._agg_draw_pending = False
147152
return
148153
try:
154+
# actually do the drawing
149155
self.draw()
150156
except Exception:
151157
# Uncaught exceptions are fatal for PyQt5, so catch them instead.
152158
traceback.print_exc()
153-
finally:
154-
self._agg_draw_pending = False
155159

156160
def blit(self, bbox=None):
157161
"""Blit the region in bbox.

0 commit comments

Comments
 (0)