I\'m trying to plot live the output of a generator.
The following code works as expected (Ctrl-C terminates execution):
import numpy as np
import pyl
Why does matplotlib care which thread does the plotting? I'm not asking how to solve this but rather why is this happening in the first place.
@Evert is right, it's not matplotlib, it's your GUI toolkit (one of the backends that matplotlib uses to create a window with a plot for you). It happens because GUI toolkits are event-driven (you don't want blocking behavior for the user interface, right?) and they have internal event loop, that controls program execution. The idea is that events are monitored by the event loop and dispatched to the callbacks. To do this, event loop should be started in the main thread, while callbacks for long-running tasks are moved to separate threads.