Hi.
I want to write a script that would make sure that all other sessions/kernels on the server are currently down. Because if they all are active, my server runs out of RAM. How do I do it? I was thinking about bash script that would run something like:
jupyter notebook list
jupyter notebook stop 8888
But this only works for jupyter. And what about JupyterHub? If I run “jupyter notebook list” I get:
Currently running servers:
http://127.0.0.1:46103/user/ubuntu/ :: /home/ubuntu
Instead of list of sessions. If I run “jupyterhub notebook list”, I get error:
[E 2021-04-26 19:00:16.966 JupyterHub app:2341] Failed to bind hub to http://127.0.0.1:8081/hub/
[E 2021-04-26 19:00:16.966 JupyterHub app:2482]
Traceback (most recent call last):
File "/home/ubuntu/miniconda3/lib/python3.7/site-packages/jupyterhub/app.py", line 2480, in launch_instance_async
await self.start()
File "/home/ubuntu/miniconda3/lib/python3.7/site-packages/jupyterhub/app.py", line 2336, in start
self.http_server.listen(port, address=ip)
File "/home/ubuntu/.local/lib/python3.7/site-packages/tornado/tcpserver.py", line 151, in listen
sockets = bind_sockets(port, address=address)
File "/home/ubuntu/.local/lib/python3.7/site-packages/tornado/netutil.py", line 161, in bind_sockets
sock.bind(sockaddr)
OSError: [Errno 98] Address already in use
This is not the complete stack, but I am trying to be short. I also tried running this code in a cell:
%%javascript
Jupyter.notebook.session.delete();
But it only stops the current notebook, but I need the opposite - to stop all the other notebooks.
I also tried inserting this code in another notebook, and then run it from the first notebook using %run "notebook location"
but it also stops the session I run it from rather than the one where this script is located. So please tell me how to close other sessions programmatically.