Question

My python version is 2.7.2

python is runing by uwsgi my nginx config is

location /{

uwsgi_pass 127.0.0.1:8888;

include uwsgi_params;

}

app.py

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

if __name__ == "__main__":
    application = tornado.web.Application([
        (r"/", MainHandler),
    ])
    application.listen(9090)
    tornado.ioloop.IOLoop.instance().start()

then I run "I run "uwsgi -s :9090 -w app"

but it throw a error

[pid: 28719|app: 0|req: 21/21] 118.207.180.64 () {38 vars in 716 bytes} [Sun Mar 23 22:44:34 2014] GET / => generated 0 bytes in 0 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0) AttributeError: application instance has no call method

how to solve it?

Was it helpful?

Solution 2

Tornado is an HTTP server, not a WSGI container (it can be used as a WSGI container, as in x3al's answer, but you lose some of its most interesting features). Use the nginx proxy_pass option instead of uwsgi_pass; a complete example nginx configuration can be found at http://www.tornadoweb.org/en/stable/overview.html#running-tornado-in-production

OTHER TIPS

import tornado.web
import tornado.wsgi
import wsgiref.simple_server

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

if __name__ == "__main__":
    application = tornado.wsgi.WSGIApplication([
        (r"/", MainHandler),
    ])
    server = wsgiref.simple_server.make_server('', 8888, application)
    server.serve_forever()

(from official docs)

The problem is that you are passing a tornado application as a uwsgi application. Here is the fix, using the WSGIAdapter available in tornado 4.0+:

import tornado.ioloop
import tornado.web
import tornado.wsgi

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")


t_application = tornado.web.Application([
    (r"/", MainHandler),
])
application = tornado.wsgi.WSGIAdapter(app)  # For wsgi layer

if __name__ == "__main__":

    t_application.listen(9090)
    tornado.ioloop.IOLoop.instance().start()

But by using Tornado via the WSGI adapter, you lose some of the most interesting features that Tornado offers. Prior to version 4.0, WSGIApplication was available.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top