2

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

Abhishek
  • 49
  • 1
  • 7
  • Is your python script reading anything from terminal? – codeforester Jun 08 '18 at 21:32
  • I am a little confused about what you are asking, I do have some subprocess and print statements in the scripts. like this; subprocess.run(['rm','-f','/home/aprakash/WISE_AP/url_list_dir_W1/merge_p1bm_frm']) subprocess.run(['rm','-f','/home/aprakash/WISE_AP/url_list_dir_W2/merge_p1bm_frm']) #!rm -rf {url_list_dir_w1}/* #!rm -rf {url_list_dir_w2}/* print(i) print("Images and mask removed. Next set will be downloaded for next AGN position") – Abhishek Jun 08 '18 at 23:27

2 Answers2

3

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 &
0

You can also "conda activate " with "&&" after "eval" below example.

Attention: pipe between test.py '>' test.txt

nohup /bin/bash -c "source ${HOME}/miniconda3/etc/profile.d/conda.sh && \
    eval $(${HOME}/miniconda3/bin/conda shell.bash hook) && \
    python test.py > test.txt 2>&1" &