简体   繁体   English

nohup不登录nohup.out

[英]nohup not logging in nohup.out

I am running a python script of web2py and want to log its output. 我正在运行web2py的python脚本,并希望记录其输出。 I am using following command nohup python /var/www/web2py/web2py.py -S cloud -M -N -R applications/cloud/private/process.py >>/var/log/web2pyserver.log 2>&1 & 我正在使用以下命令nohup python /var/www/web2py/web2py.py -S cloud -M -N -R applications/cloud/private/process.py >>/var/log/web2pyserver.log 2>&1 &

The process is running but it is not logging into the file. 该进程正在运行,但未登录到文件。 I have tried without nohup also but it is still same. 我也尝试过没有nohup,但还是一样。 The default logging of nohup in nohup.out is also not working. nohup.out中的nohup的默认日志记录也不起作用。 Any suggestion what might be going wrong? 有什么建议可能出什么问题吗?

Nothing to worry. 没什么好担心的。 Actually the python process along with nohup was logging the file in batch mode and i could see the output only after quite some time and not instantaneously. 实际上,python进程与nohup一起以批处理模式记录了文件,我只能在相当长的一段时间后才能看到输出,而不会立即看到输出。

If you've got commas in your print statements there's a good chance it's due to buffering. 如果打印语句中有逗号,则很有可能是由于缓冲。 You can put a sys command (forget which) in your code or when you run the nohup, just add the option -u and you'll disable std(in|out|err) buffering 您可以在代码中放入sys命令(忘记该命令),或者在运行nohup时,只需添加选项-u即可禁用std(in | out | err)缓冲

Don't worry about this, it is because of the buffering mechanism, run your Python script with the -u flag will solve the problem: 不用担心,这是因为有缓冲机制,使用-u标志运行Python脚本将解决此问题:

nohup python -u code.py > code.log &

or just 要不就

nohup python -u code.py &

nohup will try to create the file in the local directory. nohup将尝试在本地目录中创建文件。 Can you create a file in the folder you are running it from ? 您可以在运行文件的文件夹中创建文件吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM