2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

BashでPython3のコードをログを吐き出しながらバックグラウンドで実行する

Last updated at Posted at 2017-10-24

機械学習をしていてpythonのコードをバックグラウンドで実行し続ける必要があるときに使います。

nohup python3 -u foo.py > out.log 2> error.log &
tail -f out.log
tail -f error.log
top |grep python3 #プロセス番号を調べる
sudo renice -20 -p {プロセス番号} #優先順位を上げる

nohup: ハングアップシグナルを無視して実行し続ける。
python3 -u :標準出力と標準エラー出力のストリームのバイナリーレイヤー (buffer 属性として利用可能) がバッファされないよう強制します。それでもテキスト I/O レイヤーは、コンソールに出力する場合はラインバッファされ、日対話的なファイルにリダイレクトされた場合はブロックバッファされます

uオプションを付けると tail -f out.log で実行状況を確認できる。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?