<h3 dir="auto">Bug report</h3>
<p dir="auto">Using FuncAnimation with a generator causes a crash when the generator raises a StopIteration.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation

fig, ax = plt.subplots()
plt.plot([1,2,3],[2,4,3])
def update(frame):
	print(frame)
	return []
animation = FuncAnimation(fig, update, frames=iter(range(10)), blit=True, interval=100)
plt.show()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">animation</span> <span class="pl-k">import</span> <span class="pl-v">FuncAnimation</span>

<span class="pl-s1">fig</span>, <span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>()
<span class="pl-s1">plt</span>.<span class="pl-en">plot</span>([<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>],[<span class="pl-c1">2</span>,<span class="pl-c1">4</span>,<span class="pl-c1">3</span>])
<span class="pl-k">def</span> <span class="pl-en">update</span>(<span class="pl-s1">frame</span>):
	<span class="pl-en">print</span>(<span class="pl-s1">frame</span>)
	<span class="pl-k">return</span> []
<span class="pl-s1">animation</span> <span class="pl-c1">=</span> <span class="pl-v">FuncAnimation</span>(<span class="pl-s1">fig</span>, <span class="pl-s1">update</span>, <span class="pl-s1">frames</span><span class="pl-c1">=</span><span class="pl-en">iter</span>(<span class="pl-en">range</span>(<span class="pl-c1">10</span>)), <span class="pl-s1">blit</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">interval</span><span class="pl-c1">=</span><span class="pl-c1">100</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<p dir="auto">Output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ python animation_crash.py 
0
1
2
3
4
5
6
7
8
9
Traceback (most recent call last):
  File &quot;/usr/lib/python3.7/site-packages/matplotlib/backend_bases.py&quot;, line 1238, in _on_timer
    ret = func(*args, **kwargs)
  File &quot;/usr/lib/python3.7/site-packages/matplotlib/animation.py&quot;, line 1462, in _step
    self._init_draw()
  File &quot;/usr/lib/python3.7/site-packages/matplotlib/animation.py&quot;, line 1740, in _init_draw
    self._draw_frame(next(self.new_frame_seq()))
StopIteration
Abgebrochen (Speicherabzug geschrieben)"><pre class="notranslate"><code class="notranslate">$ python animation_crash.py 
0
1
2
3
4
5
6
7
8
9
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 1238, in _on_timer
    ret = func(*args, **kwargs)
  File "/usr/lib/python3.7/site-packages/matplotlib/animation.py", line 1462, in _step
    self._init_draw()
  File "/usr/lib/python3.7/site-packages/matplotlib/animation.py", line 1740, in _init_draw
    self._draw_frame(next(self.new_frame_seq()))
StopIteration
Abgebrochen (Speicherabzug geschrieben)
</code></pre></div>
<p dir="auto"><strong>Matplotlib version</strong><br>
Operating System: Arch linux, 64-bit<br>
Matplotlib version: 3.0.3-1 (using pacman)<br>
Matplotlib backend: Qt5Agg</p>
<p dir="auto">Coredump:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[Current thread is 1 (Thread 0x7f2d24492600 (LWP 25813))]
(gdb) info stack
#0  0x00007f2d249d0d7f in raise () at /usr/lib/libc.so.6
#1  0x00007f2d249bb672 in abort () at /usr/lib/libc.so.6
#2  0x00007f2d1f79a7fc in  () at /usr/lib/libQt5Core.so.5
#3  0x00007f2d1fd2b048 in  () at /usr/lib/python3.7/site-packages/PyQt5/QtCore.so
#4  0x00007f2d1fe8b216 in  () at /usr/lib/python3.7/site-packages/PyQt5/QtCore.so
#5  0x00007f2d1fe8bcd0 in  () at /usr/lib/python3.7/site-packages/PyQt5/QtCore.so
#6  0x00007f2d1f9bb94d in QMetaObject::activate(QObject*, int, int, void**) () at /usr/lib/libQt5Core.so.5
#7  0x00007f2d1f9c7ab8 in QTimer::timeout(QTimer::QPrivateSignal) () at /usr/lib/libQt5Core.so.5
#8  0x00007f2d1fe34c9c in  () at /usr/lib/python3.7/site-packages/PyQt5/QtCore.so
#9  0x00007f2d1f9bc10b in QObject::event(QEvent*) () at /usr/lib/libQt5Core.so.5
#10 0x00007f2d1fe34b4c in  () at /usr/lib/python3.7/site-packages/PyQt5/QtCore.so
#11 0x00007f2d1ba68e24 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#12 0x00007f2d1ba706e1 in QApplication::notify(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#13 0x00007f2d1c114b3f in  () at /usr/lib/python3.7/site-packages/PyQt5/QtWidgets.so
#14 0x00007f2d1f990e99 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/libQt5Core.so.5
#15 0x00007f2d1f9e6095 in QTimerInfoList::activateTimers() () at /usr/lib/libQt5Core.so.5
#16 0x00007f2d1f9e6922 in  () at /usr/lib/libQt5Core.so.5
#17 0x00007f2d20dd3a2f in g_main_context_dispatch () at /usr/lib/libglib-2.0.so.0
#18 0x00007f2d20dd55e9 in  () at /usr/lib/libglib-2.0.so.0
#19 0x00007f2d20dd562e in g_main_context_iteration () at /usr/lib/libglib-2.0.so.0
#20 0x00007f2d1f9e6ce9 in QEventDispatcherGlib::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) ()
    at /usr/lib/libQt5Core.so.5
#21 0x00007f2d1f98fb2c in QEventLoop::exec(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) () at /usr/lib/libQt5Core.so.5
#22 0x00007f2d1f997e36 in QCoreApplication::exec() () at /usr/lib/libQt5Core.so.5
#23 0x00007f2d1c1135cd in  () at /usr/lib/python3.7/site-packages/PyQt5/QtWidgets.so
#24 0x00007f2d24775a78 in _PyMethodDef_RawFastCallKeywords () at /usr/lib/libpython3.7m.so.1.0
#25 0x00007f2d24775d11 in _PyCFunction_FastCallKeywords () at /usr/lib/libpython3.7m.so.1.0
#26 0x00007f2d247ec8eb in _PyEval_EvalFrameDefault () at /usr/lib/libpython3.7m.so.1.0
#27 0x00007f2d247752eb in _PyFunction_FastCallKeywords () at /usr/lib/libpython3.7m.so.1.0
#28 0x00007f2d247ec2b3 in _PyEval_EvalFrameDefault () at /usr/lib/libpython3.7m.so.1.0
--Type &lt;RET&gt; for more, q to quit, c to continue without paging--
#29 0x00007f2d2472eb99 in _PyEval_EvalCodeWithName () at /usr/lib/libpython3.7m.so.1.0
#30 0x00007f2d2472fdec in _PyFunction_FastCallDict () at /usr/lib/libpython3.7m.so.1.0
#31 0x00007f2d2473f908 in _PyObject_Call_Prepend () at /usr/lib/libpython3.7m.so.1.0
#32 0x00007f2d2473033b in PyObject_Call () at /usr/lib/libpython3.7m.so.1.0
#33 0x00007f2d247e943c in _PyEval_EvalFrameDefault () at /usr/lib/libpython3.7m.so.1.0
#34 0x00007f2d2472eb99 in _PyEval_EvalCodeWithName () at /usr/lib/libpython3.7m.so.1.0
#35 0x00007f2d24775492 in _PyFunction_FastCallKeywords () at /usr/lib/libpython3.7m.so.1.0
#36 0x00007f2d247ec2b3 in _PyEval_EvalFrameDefault () at /usr/lib/libpython3.7m.so.1.0
#37 0x00007f2d2472eb99 in _PyEval_EvalCodeWithName () at /usr/lib/libpython3.7m.so.1.0
#38 0x00007f2d2472fab4 in PyEval_EvalCodeEx () at /usr/lib/libpython3.7m.so.1.0
#39 0x00007f2d2472fadc in PyEval_EvalCode () at /usr/lib/libpython3.7m.so.1.0
#40 0x00007f2d24859c94 in  () at /usr/lib/libpython3.7m.so.1.0
#41 0x00007f2d2485b8be in PyRun_FileExFlags () at /usr/lib/libpython3.7m.so.1.0
#42 0x00007f2d2485cc75 in PyRun_SimpleFileExFlags () at /usr/lib/libpython3.7m.so.1.0
#43 0x00007f2d2485eeb7 in  () at /usr/lib/libpython3.7m.so.1.0
#44 0x00007f2d2485f0fc in _Py_UnixMain () at /usr/lib/libpython3.7m.so.1.0
#45 0x00007f2d249bd223 in __libc_start_main () at /usr/lib/libc.so.6
#46 0x0000561e1056f05e in _start ()"><pre class="notranslate"><code class="notranslate">[Current thread is 1 (Thread 0x7f2d24492600 (LWP 25813))]
(gdb) info stack
#0  0x00007f2d249d0d7f in raise () at /usr/lib/libc.so.6
#1  0x00007f2d249bb672 in abort () at /usr/lib/libc.so.6
#2  0x00007f2d1f79a7fc in  () at /usr/lib/libQt5Core.so.5
#3  0x00007f2d1fd2b048 in  () at /usr/lib/python3.7/site-packages/PyQt5/QtCore.so
#4  0x00007f2d1fe8b216 in  () at /usr/lib/python3.7/site-packages/PyQt5/QtCore.so
#5  0x00007f2d1fe8bcd0 in  () at /usr/lib/python3.7/site-packages/PyQt5/QtCore.so
#6  0x00007f2d1f9bb94d in QMetaObject::activate(QObject*, int, int, void**) () at /usr/lib/libQt5Core.so.5
#7  0x00007f2d1f9c7ab8 in QTimer::timeout(QTimer::QPrivateSignal) () at /usr/lib/libQt5Core.so.5
#8  0x00007f2d1fe34c9c in  () at /usr/lib/python3.7/site-packages/PyQt5/QtCore.so
#9  0x00007f2d1f9bc10b in QObject::event(QEvent*) () at /usr/lib/libQt5Core.so.5
#10 0x00007f2d1fe34b4c in  () at /usr/lib/python3.7/site-packages/PyQt5/QtCore.so
#11 0x00007f2d1ba68e24 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#12 0x00007f2d1ba706e1 in QApplication::notify(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#13 0x00007f2d1c114b3f in  () at /usr/lib/python3.7/site-packages/PyQt5/QtWidgets.so
#14 0x00007f2d1f990e99 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/libQt5Core.so.5
#15 0x00007f2d1f9e6095 in QTimerInfoList::activateTimers() () at /usr/lib/libQt5Core.so.5
#16 0x00007f2d1f9e6922 in  () at /usr/lib/libQt5Core.so.5
#17 0x00007f2d20dd3a2f in g_main_context_dispatch () at /usr/lib/libglib-2.0.so.0
#18 0x00007f2d20dd55e9 in  () at /usr/lib/libglib-2.0.so.0
#19 0x00007f2d20dd562e in g_main_context_iteration () at /usr/lib/libglib-2.0.so.0
#20 0x00007f2d1f9e6ce9 in QEventDispatcherGlib::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) ()
    at /usr/lib/libQt5Core.so.5
#21 0x00007f2d1f98fb2c in QEventLoop::exec(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) () at /usr/lib/libQt5Core.so.5
#22 0x00007f2d1f997e36 in QCoreApplication::exec() () at /usr/lib/libQt5Core.so.5
#23 0x00007f2d1c1135cd in  () at /usr/lib/python3.7/site-packages/PyQt5/QtWidgets.so
#24 0x00007f2d24775a78 in _PyMethodDef_RawFastCallKeywords () at /usr/lib/libpython3.7m.so.1.0
#25 0x00007f2d24775d11 in _PyCFunction_FastCallKeywords () at /usr/lib/libpython3.7m.so.1.0
#26 0x00007f2d247ec8eb in _PyEval_EvalFrameDefault () at /usr/lib/libpython3.7m.so.1.0
#27 0x00007f2d247752eb in _PyFunction_FastCallKeywords () at /usr/lib/libpython3.7m.so.1.0
#28 0x00007f2d247ec2b3 in _PyEval_EvalFrameDefault () at /usr/lib/libpython3.7m.so.1.0
--Type &lt;RET&gt; for more, q to quit, c to continue without paging--
#29 0x00007f2d2472eb99 in _PyEval_EvalCodeWithName () at /usr/lib/libpython3.7m.so.1.0
#30 0x00007f2d2472fdec in _PyFunction_FastCallDict () at /usr/lib/libpython3.7m.so.1.0
#31 0x00007f2d2473f908 in _PyObject_Call_Prepend () at /usr/lib/libpython3.7m.so.1.0
#32 0x00007f2d2473033b in PyObject_Call () at /usr/lib/libpython3.7m.so.1.0
#33 0x00007f2d247e943c in _PyEval_EvalFrameDefault () at /usr/lib/libpython3.7m.so.1.0
#34 0x00007f2d2472eb99 in _PyEval_EvalCodeWithName () at /usr/lib/libpython3.7m.so.1.0
#35 0x00007f2d24775492 in _PyFunction_FastCallKeywords () at /usr/lib/libpython3.7m.so.1.0
#36 0x00007f2d247ec2b3 in _PyEval_EvalFrameDefault () at /usr/lib/libpython3.7m.so.1.0
#37 0x00007f2d2472eb99 in _PyEval_EvalCodeWithName () at /usr/lib/libpython3.7m.so.1.0
#38 0x00007f2d2472fab4 in PyEval_EvalCodeEx () at /usr/lib/libpython3.7m.so.1.0
#39 0x00007f2d2472fadc in PyEval_EvalCode () at /usr/lib/libpython3.7m.so.1.0
#40 0x00007f2d24859c94 in  () at /usr/lib/libpython3.7m.so.1.0
#41 0x00007f2d2485b8be in PyRun_FileExFlags () at /usr/lib/libpython3.7m.so.1.0
#42 0x00007f2d2485cc75 in PyRun_SimpleFileExFlags () at /usr/lib/libpython3.7m.so.1.0
#43 0x00007f2d2485eeb7 in  () at /usr/lib/libpython3.7m.so.1.0
#44 0x00007f2d2485f0fc in _Py_UnixMain () at /usr/lib/libpython3.7m.so.1.0
#45 0x00007f2d249bd223 in __libc_start_main () at /usr/lib/libc.so.6
#46 0x0000561e1056f05e in _start ()
</code></pre></div>
<p dir="auto">Using the widget "Cursor" with "use but=True" occurs the occurrence of duplicate crosshairs.<br>
When "useblit=False" work correct."Cursor" is activated in the event of a button (PyQt5)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="self.btnQuit.clicked.connect(self.cur)
******************************************
    def cur(self):
           self.cursor = Cursor(self.ax, useblit=True, color='magenta', linewidth=1)"><pre class="notranslate"><code class="notranslate">self.btnQuit.clicked.connect(self.cur)
******************************************
    def cur(self):
           self.cursor = Cursor(self.ax, useblit=True, color='magenta', linewidth=1)
</code></pre></div>
<p dir="auto">I place GIF animation as it [happens.<br>
<a href="https://ibb.co/F5Hhc46" rel="nofollow">https://ibb.co/F5Hhc46</a></p>