Very late to the party, but I actually found out that it’s not the use of set_switchinterval()
creating a problem.
It’s matplotlib.
After months of chasing this stuff - it’s a rather infrequent and difficult to reproduce bug - I went to look for what matplotlib draw_idle()
and flush_events()
are doing.
Surprise surprise, in matplotlib/backends/backend_wx.py:

This hidden wx.Yield() called in a wx.CallAfter() bombs out the entire Python process in our application.
And it also magically bombs with a RecursionError the piece of code attached (!), even though the use of flush_events()
is explicitly recommended in their page on blitting:
https://matplotlib.org/stable/users/explain/animations/blitting.html
Running that code on my machine results in this:
Traceback (most recent call last):
File "C:\Users\J0514162\WinPython39\WPy64-39100\python-3.9.10.amd64\lib\site-packages\wx\core.py", line 3427, in <lambda>
lambda event: event.callable(*event.args, **event.kw) )
File "C:\Users\j0514162\MyProjects\UAE\progress_dialog.py", line 120, in DoLongRunningTask
self.ax.draw_artist(self.line)
File "C:\Users\J0514162\WinPython39\WPy64-39100\python-3.9.10.amd64\lib\site-packages\matplotlib\axes\_base.py", line 3098, in draw_artist
a.draw(self.figure._cachedRenderer)
File "C:\Users\J0514162\WinPython39\WPy64-39100\python-3.9.10.amd64\lib\site-packages\matplotlib\artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "C:\Users\J0514162\WinPython39\WPy64-39100\python-3.9.10.amd64\lib\site-packages\matplotlib\lines.py", line 732, in draw
self.recache()
File "C:\Users\J0514162\WinPython39\WPy64-39100\python-3.9.10.amd64\lib\site-packages\matplotlib\lines.py", line 651, in recache
xconv = self.convert_xunits(self._xorig)
File "C:\Users\J0514162\WinPython39\WPy64-39100\python-3.9.10.amd64\lib\site-packages\matplotlib\artist.py", line 252, in convert_xunits
return ax.xaxis.convert_units(x)
File "C:\Users\J0514162\WinPython39\WPy64-39100\python-3.9.10.amd64\lib\site-packages\matplotlib\axis.py", line 1497, in convert_units
if munits._is_natively_supported(x):
File "C:\Users\J0514162\WinPython39\WPy64-39100\python-3.9.10.amd64\lib\site-packages\matplotlib\units.py", line 67, in _is_natively_supported
return isinstance(thisx, Number) and not isinstance(thisx, Decimal)
File "C:\Users\J0514162\WinPython39\WPy64-39100\python-3.9.10.amd64\lib\abc.py", line 119, in __instancecheck__
return _abc_instancecheck(cls, instance)
RecursionError: maximum recursion depth exceeded in comparison
Of course, if I remove the call to flush_events()
everything works all right.
progress_dialog.py (3.5 KB)