Skip to content

Commit cf54530

Browse files
committed
use KernelManager for starting a new kernel
1 parent 80eecbd commit cf54530

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

ftplugin/python/ipy.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ endif
147147
command! -nargs=* IPython :py km_from_string("<args>")
148148
command! -nargs=0 IPythonClipboard :py km_from_string(vim.eval('@+'))
149149
command! -nargs=0 IPythonXSelection :py km_from_string(vim.eval('@*'))
150-
command! -nargs=0 IPythonNew :py new_ipy()
150+
command! -nargs=* IPythonNew :py new_ipy("<args>")
151151
command! -nargs=* IPythonInterrupt :py interrupt_kernel_hack("<args>")
152152
command! -nargs=0 IPythonTerminate :py terminate_kernel_hack()
153153

ftplugin/python/vim_ipython.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,21 @@ def vim_regex_escape(x):
8282
same version of Python.
8383
"""
8484

85-
def new_ipy():
86-
from random import random
87-
from subprocess import Popen, PIPE
88-
from time import sleep
89-
import atexit
90-
fname = "vim.ipython.%s.json" % (int(random()*100000))
91-
p = Popen(["ipython", "kernel", "-f", fname], shell=False, stdout=PIPE, stdin=PIPE, stderr=PIPE)
92-
atexit.register(p.kill)
93-
sleep(3)
94-
return km_from_string(fname)
85+
def new_ipy(s=''):
86+
"""Create a new IPython kernel (optionally with extra arguments)
87+
88+
XXX: Allow passing of profile information here
89+
90+
Examples
91+
--------
92+
93+
new_ipy()
94+
95+
"""
96+
from IPython.kernel import KernelManager
97+
km = KernelManager()
98+
km.start_kernel()
99+
return km_from_string(km.connection_file)
95100

96101
def km_from_string(s=''):
97102
"""create kernel manager from IPKernelApp string

0 commit comments

Comments
 (0)