Nohup failing with Anaconda ipython

2019-08-10 23:04发布

问题:

I am trying to run a code using "nohup" command with Anaconda IPython. My code runs fine (for hours) if I run it inside ipython environment like;

irsacf00-debian:~/WISE_AP> ipython
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: %run WISE_PHOT_052918_MODULER_IRSACF.py

However, when I try to run the same code using "nohup" it breaks down with the following error message (last 2 lines). This is copy pasted from output file.

[[0;31mOSError^[[0m: [Errno 5] Input/output error

In [2]: Do you really want to exit ([y]/n)?

My nohup command looks like this;

irsacf00-debian:~/WISE_AP> nohup ipython <input_file> output_file &

My input file looks like this;

%run /home/aprakash/WISE_AP/WISE_PHOT_052918_MODULER_IRSACF.py 

I can't figure out where the code is getting stuck. Thanks for help!

Best, Abhi

回答1:

Whenever an Anaconda Environment is started, it sticks to your shell, making ipython available. (This is also true for default environment.) nohup's task is to part a process from the shell you start it with.

Do the following: Write a shell script, which first, binds conda to its shell, and then starts your program with ipython. Be aware, that conda does not support all shells, so use bash. My version looks like this:

#!/bin/bash
source /home/yOURuSERnAME/miniconda3/etc/profile.d/conda.sh
conda activate YourCondaEnvironment
ipython SomeProgramOfYours.py

(First line enforces necessary conda-compatible shell. Second line I got from Stackoverflow myself :) Here is another way of doing this combining with third line. Fourth line is what you gave nohup in your own try.)

Save as Filename.sh, start using nohup:

chmod +x Filename.sh
nohup ./Filename.sh &