如何一旦它运行在后台启动一个python脚本? [英] How to start a python script in the background once it's run?

查看:197
本文介绍了如何一旦它运行在后台启动一个python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

def main(self,argv):
    do stuff.......

if __name__ == '__main__':
    main(sys.argv[1:])

在运行我的脚本,我怎么能导致其立即运行的main()作为后台进程?
它会运行至完成,并到一个文件输出信息。

When my script is run, how can I cause it to immediately run main() as a background process? It will run to completion and outputs information to a file.

我忘了说......我们的目标是能够在任何操作系统上运行此。
我不想修改脚本调用命令行的方式,我想脚本本身以使其在后台运行。

I forgot to say...the goal is to be able to run this on any OS. I do not want to modify the way the script is called in the command line, I want the script itself to cause it to run in the background.

推荐答案

容易:

$ python yourpythonscript.py &

操作系统会处理,对于你;)当然,你必须声明,如果这是在Windows或* nix中

The os will handle that for you ;) Of course, you will have to state if this is on windows or *nix.

如果您在Windows下运行,你可能要检查的的cmd.exe 程序 - 我觉得有一个选项那里运行它的参数作为后台进程...

If you are running this under windows, you might want to check the cmd.exe program - I think there is an option there for running its arguments as a background process...

或者,如果你是在linux下运行的机器,你可以使用的ps aux检查过程| grep的yourpythonscript.py

Or if you are running this under linux machine, you can check the process by using ps aux | grep yourpythonscript.py

这篇关于如何一旦它运行在后台启动一个python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆