Hi Jupyter Community,
I am interested in setting up some very simple, low-performance "live" plots using matplotlib. Think line plot updating at ~1 Hz. Simplicity and keeping the "static" matplotlib interface intact are priorities.
My current vision for this is to write a magic function, %rerun <time>. This would declare that the code in that cell should be re-run after a specified time, perhaps defaulting to 1 or 10 seconds. The notebook could block while the cell is being re-evaluated, but should not block while waiting. This would let me write something like:
>>> %rerun
>>> data = fetch_new_data() # gets data from external server
>>> plt.plot(data)
>>> plt.show()
and get a new plot every second or so.
I am wondering if someone can give me some advice on how best to implement this in the notebook framework... I am a long time user, but unfamiliar with the architecture "under the hood". If people can anticipate issues (or explain why this is a terrible idea) that would be most appreciated.
I am currently thinking of trying to catch the end of the cell execution, and at that time, spawning a thread. This thread would just sleep for the specified time, before waking up, calling for the (re)execution of the specified cell, and then dying. Calling the cell again would spawn a new thread that would re-start the cycle. At any point, by removing or commenting the %rerun line, the user could break the cycle.
That plan brings up a number of specific questions:
* how can I find out what cell code is being executed in?
* how can I programmatically execute code in a cell?
* are there issues with spawning threads from the nb kernel?
I have searched around a bit and not found much documentation or many examples that made sense to my uninitiated mind... so thanks much for any help.
Best,
TJ