-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
24 lines (20 loc) · 849 Bytes
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def print_kernel_connection():
import json
import os
import urllib
import IPython
import re
from IPython.lib import kernel
connection_file_path = kernel.get_connection_file()
connection_file = os.path.basename(connection_file_path)
kernel_id = connection_file.split('-', 1)[1].split('.')[0]
r = urllib.request.urlopen('http://127.0.0.1:8888/api/sessions')
sessions = json.loads(r.read().decode(r.info().get_param('charset') or 'utf-8'))
for sess in sessions:
if sess['kernel']['id'] == kernel_id:
jpath = sess['notebook']['path']
break
name = re.search('.*/(.*).ipynb', jpath).group(1)
print('PROMPT_COMMAND=\'echo -ne "\\033]0; %s \\007"\''%name)
print('ssh levin@10.0.50.40 -t \'ipython console --existing %s \''%(connection_file_path))
print('')