Sending ipython to the background with control-z - ipython

I frequently need to access the shell directly. In the past few weeks, every time I've used Ctrl+Z to send an ipython task to the background and tried to resuscitate it with fg, it has failed. I suspect this has to do with some recent change in ipython. Is there any way to make ipython foregroundable again?
EDIT: ipython version 2.2.0, and the failure is that the terminal hangs and never recovers. All I can do after fg is send ipython to the background again with Ctrl+Z and then kill it.
EDIT: Apparently this is a problem with anaconda: if I try to start ipython, it insists on wrapping it in a shell and then a python.app:
37463 ttys008 0:00.00 /bin/bash /Users/adam/anaconda/envs/astropy27/bin/python.app /Users/adam/anaconda/envs/astropy27/bin/ipython
37464 ttys008 0:00.40 /Users/adam/anaconda/envs/astropy27/python.app/Contents/MacOS/python /Users/adam/anaconda/envs/astropy27/bin/ipython
so it appears that Ctrl+Z is sending only one process to the background, perhaps? Is there a reason for this behavior, and can I disable it?

A workaround has been posted here:
https://github.com/ContinuumIO/anaconda-issues/issues/191
You can either kill -CONT {pid} explicitly before using fg, or (better), use fg %{jobid}. The former required that I also reset the terminal, while the latter just worked.

The workaround at https://github.com/ContinuumIO/anaconda-issues/issues/191
did not work for me, but I managed to workaround by below alias:
alias ipython='python -m IPython'

Related

FISH error upon startup to access a file that does exist

On an Ubuntu 14.04, I have started to receive the following warning (or error) each time I start a new session in terminal :
Unable to make or open a FIFO for universal variables with path '/run/user/0/fishd.12c79b706e7a.notifier': Permission denied
When I try to look into this file, the file does not exist at all.
I had a similar problem setting my terminal to fish in IntelliJ IDEA on Manjaro.
Every time I opened up the terminal, it kept printing the following error message;
Unable to open universal variable file '/opt/intellij-idea-ultimate-edition/plugins/terminal/fish/fish_variables': Permission denied
The solution I used, while not ideal did stop the error message - it's trying to write to a root controlled location from user land. from the terminal type the following command:
chown -R USER:USER /opt/intellij-idea-ultimate-edition/plugins/terminal/fish
This is fish issue #2222.
The problem seems to be that you get the wrong value for $XDG_RUNTIME_DIR. In that issue the reporter said su -l caused it, which, unlike what the documentation said, did not clear $XDG_RUNTIME_DIR or set it again to the wrong value.
I get a much more benign issue on fish 2.2.0 (and current git):
fish: No TTY for interactive shell (tcgetpgrp failed)
setpgid: Inappropriate ioctl for device
which seems not to break anything, so I can only recommend upgrading.

Tmux breaks "who am i" (who -m)

Within tmux when I type "who am i" (more formally, who -m) I get a blank response.
Obviously this would be a minor niggle -- except that our vendor's code uses it to establish user ID, and won't run without it. So I can't use my normal development tools within tmux.
I'm on Centos 6.5 and Centos 7. This is reproducible on both.
I know that with screen this is a known issue caused by screen not starting shells in login mode? But tmux does start shells in login mode; I can confirm that, because I can see that it's running my .profile again.
This appears to be a genuine bug, since it was specifically mentioned in the changelogs for tmux 2.0 -- which fixes it.

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.
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")

Starting mongo then leaving shell without shutting down the server

Hi Guys I start Mongo remotely on Putty SSH and after mongod, it says "listening for ports" but I can't then leave without shutting down the server. how do I do that?
On linux, look up the Screen module. There are other alternatives that do the same thing as well. It basically makes a saved session that you can reattach to later -- I use it extensively to run long tests/services that I can reattach to quickly.
The Starting and Stopping Mongo documentation article explains several options, one of which is using the --fork command line parameter to start mongod as a background process. Additionally, you can look into using service controls provided by your operating system (e.g. Windows services, init.d, upstart).
You can make a quick Mongo service script in either Windows or Linux.
You can also press CTRL+Z which will basically switch it to a background process. This basically gives you back temrinal (or at least does for me).
I also like "Screen". It is quite powerful and easy to navigate so I would personally give that a try.

ipython: %paste over ssh connection

In ipython >=0.11, the %paste command is required to paste indented commands. However, if I run an ipython shell in a remote terminal, the buffer %paste refers to is on the remote machine rather than the local machine. Is there any way around this?
I think this is exactly what %cpaste is for (I am always forgetting about all the things IPython does). %cpaste enters a state allowing you to paste already formatted or indented code, and it will strip leading indentation and prompts, so you can copy/paste indented code from files, or even from an interactive Python session including leading >>> or In [1] which will be stripped.
Not a brilliant solution, but I think this will work:
Use %autoindent to turn off autoindenting, type if True: and press enter. Then paste your indented code.
I think it should be possible to write an IPython extension to handle this better. I'll try to get round to looking into it. I've made an issue.
If you use IPython a lot, you may want to get the new kernel/client architecture working - it should be possible to tunnel the connections over SSH, so you can use the Qt console on your local machine, talking to a kernel on a server. But that might take a bit of fiddling to get in place.