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

Support connecting to existing ipython session. #71

Merged
merged 2 commits into from Jun 28, 2017
Jump to file or symbol
Failed to load files and symbols.
+18 −7
Diff settings

Always

Just for now

Copy path View file
@@ -104,6 +104,8 @@
This is the most basic ipython block. You *must* provide a session
argument. You can name the session if you wish to separate state.
You can also pass an connection json of existing ipython session
as a session name in order to connect to it.
#+BEGIN_SRC org
,#+BEGIN_SRC ipython :session
Copy path View file
@@ -53,7 +53,11 @@ def msg_router(name, ch):
clients = {}
def create_client(name):
cf = find_connection_file('emacs-' + name)
if name.endswith('.json'):
# Received an existing kernel we should connect to.
cf = find_connection_file(name)
else:
cf = find_connection_file('emacs-' + name)
c = client.BlockingKernelClient(connection_file=cf)
c.load_connection_file()
c.start_channels()
@@ -117,10 +121,10 @@ def get(self):
def make_app():
return tornado.web.Application([
tornado.web.url(r"/execute/(\w+)", ExecuteHandler),
tornado.web.url(r"/inspect/(\w+)", InspectHandler),
tornado.web.url(r"/execute/([\w\-\.]+)", ExecuteHandler),
tornado.web.url(r"/inspect/([\w\-\.]+)", InspectHandler),
tornado.web.url(r"/debug", DebugHandler),
])
])
def main(args):
parser = argparse.ArgumentParser()
Copy path View file
@@ -129,7 +129,11 @@
;;; process management
(defun ob-ipython--kernel-repl-cmd (name)
(list "ipython" "console" "--existing" (format "emacs-%s.json" name)))
(let ((conn-json
(if (s-ends-with-p ".json" name)
name
(format "emacs-%s.json" name))))
(list "ipython" "console" "--existing" conn-json)))
(defun ob-ipython--create-process (name cmd)
(apply 'start-process name (format "*ob-ipython-%s*" name) (car cmd) (cdr cmd)))
@@ -345,8 +349,9 @@ VARS contains resolved variable references"
(error "ob-ipython currently only supports evaluation using a session.
Make sure your src block has a :session param.")
(ob-ipython--create-client-driver)
(ob-ipython--create-kernel-driver (ob-ipython--normalize-session session)
(cdr (assoc :kernel params)))
(when (not (s-ends-with-p ".json" session))
(ob-ipython--create-kernel-driver (ob-ipython--normalize-session session)
(cdr (assoc :kernel params))))
(ob-ipython--create-repl (ob-ipython--normalize-session session))))
(provide 'ob-ipython)
ProTip! Use n and p to navigate between commits in a pull request.