Skip to content

[Bug]: Swallowed error in Jupyter+Matplotlib FuncAnimation. #27822

@Carreau

Description

@Carreau

Bug summary

In some case it seem that FuncAnimation in Jupyter + matplotlib widgets + funcanimation just swallow error, leading to hard to debug error as to why animations don't show.

Code for reproduction

Here is a dumb animation where the animate part, raise an error (in the original code this was a typo so a NameError, but for readability, here an assert).

%matplotlib widget

import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation 

Nx = 101

x = list(range(10))
def u_func(t):         
    return [x+t//10 for x in range(10)]

fig, ax = plt.subplots()
dt_ms =  50

u0 = u_func(0)
line = ax.plot(x, u0)[0] 



def animate(n):
    """ Fonction principale qui met à jour l'image d'un pas de temps à un autre
    Entrée : 
        n : pas de temps courant
    """
    line.set_ydata(u_func(n))
    assert False, "anything that triggers and error like a typo"
    return line
 
anim = FuncAnimation(fig, animate, interval=dt_ms, frames=50, repeat=True)

Actual outcome

Animation not happening

Expected outcome

Show at least a warnings that the animate function raised

Additional information

I tried to print a trace as to when the animate function get called see

https://gist.github.com/Carreau/e6510855ecab88630f1ea5985a98358c

This is likely multiple problems, matpltolib may want have an explicit warning that animate crash, but ipympl, comm, and ipykernel itself should likely have error messages as well.

Operating system

osx

Matplotlib Version

3.8.3

Matplotlib Backend

module://ipympl.backend_nbagg

Python version

3.11

Jupyter version

4.0.9

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions