nohup nohup: ignoring input


 

import time

while True:
    time.sleep(3)
    print("pass ")

 

[root@VM-8-12-centos Recorder]# 
[root@VM-8-12-centos Recorder]# nohup python test.py > tes.txt 2>&1 &
[1] 13596

[root@VM-8-12-centos Recorder]# 
[root@VM-8-12-centos Recorder]# more tes.txt
nohup: ignoring input
[root@VM-8-12-centos Recorder]# 

 

[root@VM-8-12-centos Recorder]# cat > a.py
# script.py
import time 
print("Running in the background")
time.sleep(10)  # 休眠10秒
print("Finished sleeping")

[root@VM-8-12-centos Recorder]# nohup python a.py > a.txt 2>&1 &
[2] 20380


[root@VM-8-12-centos Recorder]# more a.txt
nohup: ignoring input

 [root@VM-8-12-centos Recorder]# more a.txt
nohup: ignoring input
Running in the background
Finished sleeping

 


 

 原因:

只有全部  time.sleep  都运行完了,才能开始输出内容到  tes.txt 文件中。

即使把print放到很靠前的位置,把time.sleep 放到最后一行。

如下:

# script.py
import time
 
print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(1)  # 休眠10秒

print("Running in the background")

print("Finished sleeping")

time.sleep(11)  # 休眠10秒

 

解决方法:

替代print为输出到文件中(专门做一个日志文件)。

Nohup + time.sleep 出现问题。修改为输出到文件。Logs_To_File_and_Screen

 

posted @ 2024-10-10 21:09  emanlee  阅读(23)  评论(0编辑  收藏  举报