Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

synchronizing history when ipython notebook and console are connected to the same kernel

I have ipython notebook running on a remote server, i.e.

ipython notebook --profile=nbserver

which I access from my local machine. Further, I ssh to the remote server from my machine, and start ipython console (terminal) on that server. I have found following command to work well:

ipython console --existing \
~/.config/ipython/profile_nbserver/security/kernel-*.json

Now I am connected to the same remote kernel from two different clients (lets call them browser and terminal). Everything works well, except one annoying detail:

1) in browser, I type a=1

2) in terminal, I type b=2

3) in both clients I can see both commands using %history. But when I want to cycle through the history (in terminal) using Up, it only shows the commands which have been typed in the terminal, (i.e b=2). Similarly, I am unable to use a + PageDown in the terminal, to go back in history and find the command starting with a.

From what I understand, my two clients are using two separate history files history.sqlite. But why does %history show all commands ?

Question: Is there any way to configure using one history.sqlite for both clients ?

I find, having easy access to history is absolutely crucial. Moreover, I see using both terminal and browser as complementary, they both have tradeoffs and are best used combined.

like image 663
Martin Vegter Avatar asked Aug 09 '14 17:08

Martin Vegter


People also ask

Can you use multiple kernels within the same Jupyter Notebook?

SoS Notebook is an extension to Jupyter Notebook that allows the use of multiple kernels in one notebook. More importantly, it allows the exchange of data among subkernels so that you can, for example, preprocess data using Bash, analyze the processed data in Python, and plot the results in R.

What is %% capture in Python?

IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. from __future__ import print_function import sys. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.

What does %% do in Jupyter Notebook?

Both ! and % allow you to run shell commands from a Jupyter notebook. % is provided by the IPython kernel and allows you to run "magic commands", many of which include well-known shell commands. ! , provided by Jupyter, allows shell commands to be run within cells.


1 Answers

You can set where the history gets loaded either by setting it at the terminal:

ipython --HistoryManager.hist_file=$HOME/ipython_hist.sqlite

or within the ipython config files:

import os
c.HistoryManager.hist_file=os.path.expanduser("~/ipython_hist.sqlite")
like image 164
Probably rgbkrk Avatar answered Oct 27 '22 16:10

Probably rgbkrk