LoginSignup
7
7

More than 5 years have passed since last update.

Amazon Linux AMI on EC2でPython2.7のバッチをnohupで流す

Last updated at Posted at 2015-07-02

EC2 + Amazon Linux AMIでのpython環境構築について調べていたのですが、時期によって情報に錯綜があって混乱したので、個人的にまとめ。

2015年7月頭時点の「Amazon Linux AMI 2015.03」では、python2.7がデフォルトになってるみたいですね。

sudo yum -y update
python --version
> Python 2.7.9

ただ、pipでpandasを入れようとして、いろいろ足りないとかエラーが。makeとかgccとか別途入れる必要あるようで。以下でそれっぽいもの一通り入れてくれます。

sudo yum -y groupinstall "Development Tools"
sudo pip install pandas

ついでに。

nohupしてバッチぶん投げて帰って家で状況確認しようと思って、以下のようにいつもの感じでnohup付きで実行したら、tail -f してもprintの結果とか何にも出てこない。

nohup python my.py > out.log 2>&1 &

以下によると、デフォルトだと処理終了までバッファされちゃうので、-uをつけろってことみたいですね。

stackoverflow: Python - Nohup is not writing log to output file

-uをつけて、無事期待通りの挙動をしてくれております。

nohup python -u my.py > out.log 2>&1 &

オプションの詳細については本家のリファレンスで。

-u
stdin, stdout, stderr のバッファを強制的に無効にします。関係するシステムでは、 stdin, stdout, stderr をバイナリモードにします。
7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7