-
Notifications
You must be signed in to change notification settings - Fork 1
/
jpsnd
executable file
·40 lines (34 loc) · 1.14 KB
/
jpsnd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# send commands to jupyter kernel
#
# USAGE:
# echo 'a=1' | ./jpsnd # send to most recent kernel
# echo 'a=1' | ./jpsnd 2289 # send to specific kernel
# Find kernels:
# ls /run/user/$(id -u)/jupyter
# %connect_info
# resources:
# https://blogs.aalto.fi/marijn/2017/11/13/integrating-vim-and-jupyter-qtconsole/
# https://stackoverflow.com/questions/9977446/connecting-to-a-remote-ipython-instance/35792945#35792945
# https://github.com/jupyter/jupyter_kernel_test/blob/master/jupyter_kernel_test/__init__.py
import jupyter_client
# from tornado.ioloop import IOLoop
import sys
if len(sys.argv) < 2:
cf = jupyter_client.find_connection_file()
else:
cf = jupyter_client.find_connection_file(sys.argv[1])
kc = jupyter_client.BlockingKernelClient(connection_file=cf)
kc.load_connection_file()
send = sys.stdin.read()
if len(send) > 0:
msgs = []
f = kc.execute(send)
# kc.loop_client.add_handler(lambda x, y: msgs.append(x), 'iopub')
# r = IOLoop.current().run_sync(lambda: f, timeout=15)
# print(msgs)
else:
# TODO: paste from clipboard if nothing in pipe
pass