Search code examples
pythongoogle-app-enginewebserverhostingtornado

where I host apps developed using tornado webserver


Is It there any hosting service for hosting simple apps developed using tornado.(Like we hosting in Google App Engine). Is it possible to host on Google App Engine?.The Apps is just like some student datas(adding,removing,searching etc).I'm devoloped using python.

Thanks in advance


Solution

  • It is absolutely possible to host Tornado apps on App Engine; however, there are a couple caveats you need to keep in mind:

    • App Engine is deploying everything through WSGI, which means that you can't take the advantage of Tornado's async features, providing that WSGI is asynchronous by design. If you can live with that, you need to wrap your app with WSGIAdapter:

      app = tornado.web.Application(url_list, **server_settings)
      
      if __name__ == '__main__':
          # start the server if run directly
          import tornado.httpserver
          http_server = tornado.httpserver.HTTPServer(app)
          http_server.listen(8080, address='localhost')
          tornado.ioloop.IOLoop.instance().start()
      else:
          # wrap as WSGI
          import tornado.wsgi
          app = tornado.wsgi.WSGIAdapter(app)
      
    • App Engine requires all the app-specific libraries to be vendored within your source, so you can't use virtualenvs nor install libraries via pip, and all your modules must be pure Python. The best approach is to have a special directory, not tracked by your source control, and to install everything there locally with pip install -U -t lib/ -r requirements.txt (assuming the directory is called lib. Of course, you need to make your code aware of this directory by adding this somewhere in your app's configuration:

      sys.path.insert(0, os.path.join(os.path.abspath('.'), 'lib'))