网站制作学习网Python→正文:python 后台执行
字体:

python 后台执行

Python 2022/7/13 12:17:03  点击:不统计

原文是网站制作学习网的FoAsP.cn

做python 内容是,需要python在后台执行,实际操作过程只需要linux 执行一个nohup 命令即可。

 

首先看结论,怎么实现python后台执行

命令行运行:

python pythonfilename.py >log.log 2>&1 &

这样就会在后台运行,如果想让它回到前台

直接输入 fg 回车即可。

可以输入jobs 查看所有的后台任务

也可以通过 查看进程号,进行进程关闭。

 

其次,我们看一下nohup的命令格式,学习一下linux 后台执行命令

默认的nohup命令如下:

nohup command & 

它会吧日志输出到nohup.out 文件中

 

如果是指定日志文件,则

nohup command > 指定文件.file 2>&1 &

在上面的例子中,0 – stdin (standard input),1 – stdout (standard output),2 – stderr (standard error) ;

2>&1是将标准错误(2)重定向到标准输出(&1),标准输出(&1)再被重定向输入到myout.file文件中。

 



原载于:文章来源:www.forasp.cn网站制作学习

·上一篇:python 调用 nodejs extjs ReferenceError: TextEncoder is not defined >>    ·下一篇:PackagesNotFoundError: The following packages are not available from c >>
推荐文章
最新文章