简体   繁体   中英

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. I got a web app from below link. How to connect a webpage with python to 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 ". 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.

Now the issues is
Web Page Stops when i close my SSH Session :(
How do i run it in the background? tried & and that didn't help.

Thanks and Regards, 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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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