Python BaseHTTP在启动nginx或其他服务时受到攻击

Python BaseHTTP在启动nginx或其他服务时受到攻击,python,Python,我使用BaseHTTP,因为它非常简单。如果我用错了,请给我建议 if self.path.endswith("nginxstart"): xxxxxx status=os.system("/home/karthik/nginx/nginx-1.0.4/sbin/nginx"); #tried ls -l and works self.wfile.write("nginx restarted") nginx启动了,但在我关闭python服务器之前,不会将nginx重

我使用BaseHTTP,因为它非常简单。如果我用错了,请给我建议

if self.path.endswith("nginxstart"):
    xxxxxx 
    status=os.system("/home/karthik/nginx/nginx-1.0.4/sbin/nginx");  #tried ls -l and works
    self.wfile.write("nginx restarted")
nginx启动了,但在我关闭python服务器之前,不会将nginx重新启动写入浏览器。 当我使用netstat-anp | grep'nginx's pid'时,有两个侦听端口:

python服务器正在监听端口8000:我已经杀死了它 nginx应该在其中运行。 如果我运行简单的shell命令os.systemls-l等等,效果会很好

如果我运行与普通python脚本相同的脚本,而不是作为web服务器运行,效果会非常好

尝试启动一些其他服务也不起作用。 我用try-catch试过了,catch部分没有被执行。 浏览器永远处于连接/接收状态


有什么帮助吗?

您的代码被卡住了,因为os.system会阻塞,直到命令完成。因此,如果nginx命令不在后台运行,那么进程将不会结束,代码将被卡住

另一种方法是使用模块:


谢谢你的回复。我仍然尝试过,我也尝试过subprocess.call,有nginx&。当我打电话时,我看到进程仍在运行!但当我再次打电话时,它不会显示,来自浏览器的电话只是挂断。浏览器没有响应。作为一个普通的python程序,它可以正常工作。当我杀死我的python服务器baseHttp netstat-lnp | grep 8008 tcp 0.0.0.0:8008 0.0.0.0:*侦听11007/python NGINX在pid 11009 netstat-lnp | grep 11009 tcp 0.0.0.0:8085 0.0.0:*侦听11009/在杀死BASEHTTP kill 11007之后,现在在11009下有两个端口监听netstat-lnp | grep 11009 tcp 0.0.0.0:8008 0.0.0:*监听11009/tcp 0.0.0.0:8085 0.0.0.0:*监听11009/是由nginx执行的python吗pythonweb服务器本身提供一个页面。单击按钮时,nginx作为python_web_服务器的子级启动。但是刚刚发现nginx进程是。我尝试过os.system./nginx、Popen、subprocess.call。
from subprocess import Popen

# start a new command
cmd = Popen("/home/.../nginx", shell=True)

# you can regulary check if the command is still running with:
cmd.poll()
if cmd.returncode is None:
    print "process is still running !"
else:
    print "process exited with code %d" % cmd.returncode

# or even kill it
cmd.kill()