简体   繁体   English

用于运行Python脚本的Web应用-作为后台进程运行。

[英]Web App to run Python Scripts - Run as a background process.

I have a python script which i want a user to run in the server, with out giving a SSH Login permission. 我有一个python脚本,希望用户在服务器中运行,而没有提供SSH登录权限。 I got a web app from below link. 我从下面的链接获得了一个Web应用程序。 How to connect a webpage with python to mod_wsgi? 如何将使用python的网页连接到mod_wsgi?

Here is the modified version that's working for me 这是对我有用的修改后的版本


 import web

    class Echo:
        def GET(self):
            return """<html><form name="script-input-form" action="/" method="post">
    <p><label for="Import"><font color=green><b>Press the button to import CSV</b></font)</label>
    Import: <input type="submit" value="ImportCSV"></p>
    </form><html>"""

    def POST(self):
        data = web.input()
        return data
        obj = compile('execfile("importcsv.py")', '', 'exec')
        result = eval(obj, globals(), locals())
        web.seeother('/')
urls = (
  '/.*', Echo,
)
if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()
else:
    app = web.application(urls, globals()).wsgifunc()

Script i stored in site.py and I am executing it with the command " python2.7 site.py 10.10.10.19:8080 ". 我将脚本存储在site.py中,并使用命令“ python2.7 site.py 10.10.10.19:8080 ”执行该脚本。 When user access 10.10.10.19:8080 he can see the web page and click on the button when he wants the code to be executed. 当用户访问10.10.10.19:8080时,他可以看到网页并在想要执行代码时单击按钮。

Now the issues is 现在的问题是
Web Page Stops when i close my SSH Session :( 当我关闭SSH会话时网页停止:(
How do i run it in the background? 我如何在后台运行它? tried & and that didn't help. 尝试了&并且没有帮助。

Thanks and Regards, Rijil Hari 感谢和问候,Rijil Hari

It looks like you want to spawn a new process, since the current process is attached to the shell (alternatively, you could detach the terminal from the ssh session). 看起来您想生成一个新进程,因为当前进程已附加到外壳程序(或者,您可以将终端与ssh会话分离)。

To spawn a new process you can refer to bash spawn new process , or you can try this option instead which keeps your session alive after you disconnect. 要生成新进程,可以参考bash spawn new process ,也可以尝试使用此选项 ,以使断开连接后的会话保持活动状态。

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

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