2017-04-21 72 views
0

如何在ubuntu後臺運行python腳本?我試圖用「&」,例如:如何在ubuntu後臺運行python腳本?

python3 test.py &

但是當我關閉終端,這個過程似乎被關閉,以及因爲我不能得到任何更新此測試腳本的日誌。

+0

添加'nohup' http://stackoverflow.com/questions/32784462/how-to-run-multiple-php-scripts-在背景上的ubuntu – Serge

+0

閱讀此答案[http://stackoverflow.com/questions/2975624/how-to-run-a-python-script-in-the-background-even-after-i-logout- ssh](http://stackoverflow.com/questions/2975624/how-to-run-a-python-script-in-the-background-even-after-i-logout-ssh) – Minji

回答

1

你可以使用setsid。在你的情況下運行:

setsid python test.py 

或者,如評論中提到的,你可以使用nohup。

nohup python test.py 

你可以看到這個答案它們之間的區別:What's the difference between nohup and a daemon?

+0

謝謝,它的作品。 –

1

我想你正在尋找像Serge提到的nohup命令。

answer看起來像你想

+0

非常感謝。 –