stdout をフラッシュする必要があります 印刷後:sys.stdout.flush();そうしないと、stdout バッファーがいっぱいになるまでに時間がかかります。
stdout のバッファリングを解除するために Python に -u フラグを渡します
nohup python -u test.py &
それ以外の場合、Python は stdout をバッファリングします。これにはコードの変更は必要ありません。
マニュアルページから:
-u Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, also put stdin, stdout
and stderr in binary mode. Note that there is internal buffering in xreadlines(), readlines() and file-object
iterators ("for line in sys.stdin") which is not influenced by this option. To work around this, you will want
to use "sys.stdin.readline()" inside a "while 1:" loop.
ちょうど同様の問題がありました。私のスクリプトは nohup なしでうまくいきました。 nohup を使用すると、スクリプトは SyntaxError でクラッシュします。
問題は、python のエイリアスを使用する nohup の実行コンテキストでした。 python2 にマッピング python3 の代わりに .
python3 を指定して修正 python の代わりに .