【问题标题】:Nohup failing with Anaconda ipythonNohup 使用 Anaconda ipython 失败
【发布时间】:2018-06-08 20:55:27
【问题描述】:

我正在尝试使用 Anaconda IPython 的“nohup”命令运行代码。 如果我在 ipython 环境中运行它,我的代码运行良好(几个小时);

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

但是,当我尝试使用“nohup”运行相同的代码时,它会出现以下错误消息(最后 2 行)。这是从输出文件复制粘贴的。

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

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

我的 nohup 命令如下所示;

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

我的输入文件是这样的;

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

我无法弄清楚代码卡在哪里。感谢您的帮助!

最好, 阿比

【问题讨论】:

  • 你的 python 脚本是否从终端读取任何内容?
  • 我对你的要求有点困惑,我确实在脚本中有一些子进程和打印语句。像这样; 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("图像和蒙版已移除。下一组将被下载用于下一个 AGN 位置")

标签: linux python-3.x anaconda nohup


【解决方案1】:

每当启动 Anaconda 环境时,它都会附着在您的 shell 上,从而使 ipython 可用。 (默认环境也是如此。) nohup 的任务是从你启动它的 shell 中分离一个进程。

执行以下操作:编写一个 shell 脚本,首先将 conda 绑定到它的 shell,然后使用 ipython 启动您的程序。请注意,conda 不支持所有 shell,因此请使用 bash。我的版本是这样的:

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

(第一行强制执行必要的 conda 兼容 shell。第二行是我自己得到的 from Stackoverflow :) Here 是与第三行结合的另一种方法。第四行是您在自己的尝试中给出的 nohup。)

另存为 Filename.sh,开始使用 nohup:

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

【讨论】:

    【解决方案2】:

    您也可以在下面的示例中的“eval”之后使用“&&”来“conda activate”。

    注意: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" &
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-25
      • 1970-01-01
      • 1970-01-01
      • 2018-04-07
      • 2019-06-07
      • 1970-01-01
      • 2019-03-14
      • 2016-01-07
      相关资源
      最近更新 更多