diff --git a/puppet_master.py b/puppet_master.py index c09e2af..5348840 100644 --- a/puppet_master.py +++ b/puppet_master.py @@ -25,6 +25,8 @@ def __init__(self, DaemonCls, configfile, pidfile): self._updating = False def start(self): + # Kill all robot instances in Jupyter that could interfere with poppy-services + self._stop_jupyter_kernels("http://localhost:8888") self.daemon.start() @property @@ -106,6 +108,18 @@ def send_value(self, motor, register, value): r = requests.post(url.format(motor, register), json=value) return r + def _stop_jupyter_kernels(self, base_url): + """ + Shutdown Jupyter notebook kernels using Jupyter REST API + """ + # A GET request on main page is needed to have the xsrf token in cookies + client = requests.session() + client.get(base_url) + kernels = client.get("%s/api/kernels" % base_url).json() + for k in kernels: + client.delete("%s/api/kernels/%s" % (base_url, k["id"]), + data = {"_xsrf": client.cookies['_xsrf']}) + if __name__ == '__main__': import sys