I’m looking at implementing code carbon in my Jupyter notebooks. It’s a tool that tracks CO2 emissions from running code. Tracking emissions is relatively simple: you set up a tracker, run
tracker.start() at the top of the notebook, and run
tracker.end() at the end of the notebook.
Sometimes, however, I exit notebooks without running all cells, so I occasionally won’t run the
tracker.stop() command that I need to log the emissions from that notebook session.
My hope is that there’s some way to define custom code that will be run when the kernel is shutdown. That way I make sure to call
tracker.stop(). But I don’t know whether it’s possible to do this.