【问题标题】:Check if your python code is running in the background on EC2检查您的 python 代码是否在 EC2 的后台运行
【发布时间】:2020-05-27 23:52:59
【问题描述】:

我在 EC2 ubutuntu 服务器上运行了一个 python 代码,然后关闭了我的笔记本电脑,因此我的 EC2 中的 ssh 停止了。我现在想检查一下 Python 代码是否已在集群上运行完毕。
所以我 ssh-ed 进入集群并输入以下命令:我得到以下输出。
这是否意味着代码已经运行完毕?

ubuntu@ip-xxx-xx-xx-xx:~$ ps ax | grep python3
  760 ?        Ssl    0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
  826 ?        Ssl    0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
21408 pts/0    S+     0:00 grep --color=auto python3

我还检查了实际文件:

ubuntu@ip-xxx-xx-xx-xx:~$ ps ax | grep run_file.py 
21406 pts/0    S+     0:00 grep --color=auto run_file.py

【问题讨论】:

    标签: linux bash amazon-ec2


    【解决方案1】:

    这更像是一个 Linux / BASH 问题,而不是一个 python 问题。

    当您关闭 SSH 会话时,您的脚本很可能停止执行。您需要在 tmux、screen 或使用 nohup 命令运行脚本,这样当您退出会话时,脚本会继续运行。

    我更喜欢screen,但如果尚未安装,则需要安装它。与tmux 相同。 nohup 应该在大多数 Linux 安装中可用。

    nohup python script.py &
    

    man nohup了解更多信息

    【讨论】:

    • 谢谢。下次我会用那个。并更新了标签!
    猜你喜欢
    • 1970-01-01
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    • 2014-01-03
    • 1970-01-01
    • 2012-07-24
    相关资源
    最近更新 更多