Skip to content

Kill all Jupyter notebook before starting PoppyDaemon #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions puppet_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down