Web App to run Python Scripts - Run as a background process.
Question: 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?](http://stackoverflow.com/questions/16122770/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


Answer: 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](http://stackoverflow.com/questions/2429763/new-application-process-
from-bash-shell), or you can try [this option
instead](http://askubuntu.com/questions/8653/how-to-keep-processes-running-
after-ending-ssh-session) which keeps your session alive after you disconnect.

