0

I just created a lightweight web.py web app that I was able to successfully host on an Amazon EC2 instance. I am able to serve the webpage just fine with the following command:

python bin/app.py &

I specifically added the ampersand at the end to ensure that the process continues in the background, and the web app is served even when I close the ssh connection to my EC2 instance. However, I notice that after a while, on trying to access the same page, I start to get some error messages. Could it be that somehow EC2 takes away the resources from my instance after a while, which could be causing this? Also is my approach to create a persistent web service on EC2 fine, or is there a better approach?

The error that I see is:

Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/lpthw.web-1.1-py2.6.egg/web/wsgiserver/__init__.py", line 1245, in communicate
req.respond()
  File "/usr/lib/python2.6/site-packages/lpthw.web-1.1-py2.6.egg/web/wsgiserver/__init__.py", line 775, in respond
self.server.gateway(self).respond()
  File "/usr/lib/python2.6/site-packages/lpthw.web-1.1-py2.6.egg/web/wsgiserver/__init__.py", line 2018, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
  File "/usr/lib/python2.6/site-packages/lpthw.web-1.1-py2.6.egg/web/httpserver.py", line 268, in __call__
return self.app(environ, xstart_response)
  File "/usr/lib/python2.6/site-packages/lpthw.web-1.1-py2.6.egg/web/httpserver.py", line 236, in __call__
return self.app(environ, start_response)
  File "/usr/lib/python2.6/site-packages/lpthw.web-1.1-py2.6.egg/web/application.py", line 287, in wsgi
start_resp(status, headers)
  File "/usr/lib/python2.6/site-packages/lpthw.web-1.1-py2.6.egg/web/httpserver.py", line 265, in xstart_response
self.log(status, environ)
  File "/usr/lib/python2.6/site-packages/lpthw.web-1.1-py2.6.egg/web/httpserver.py", line 281, in log
print >> outfile, utils.safestr(msg)
IOError: [Errno 5] Input/output error
KT100
  • 1,381
  • 5
  • 17
  • 27

2 Answers2

2

FastCGI with lighttpd is the recommended way of using web.py in production. I recommend the web.py documentation on deployment: http://webpy.org/deployment

Uilton Dutra
  • 394
  • 1
  • 4
  • 2
    I think this information is a bit outdated. I would not recommend deployment with fastcgi and flup because it is discontinued. I deploy my apps with Apache2 + mod_wsgi (simple to setup) or nginx + uwsgi (better performance). Check this question http://stackoverflow.com/questions/12305146/python-2-7-with-webpy-flup-or-modwsgi – Andrey Kuzmin Feb 08 '13 at 06:54
2

Use the No Hangup command to ensure a background process isn't killed when you close the SSH session.

$ nohup python bin/app.py &
doughgle
  • 827
  • 1
  • 9
  • 18