0
votes

after pip install flask pip install pynba

i try following code


    import flask
    import pynba.wsgi

    class FlaskWithPynba(flask.Flask):
        @pynba.wsgi.monitor(('localhost', 30002))
        def wsgi_app(self, environ, start_response):
            super(FlaskWithPynba, self).wsgi_app(environ, start_response)

    app = FlaskWithPynba('myapp')

but have some errors when call app.run()


    Traceback (most recent call last):
      File "/home/coffee/venv/local/lib/python2.7/site-packages/flask/app.py", 
    line 1836, in __call__
        return self.wsgi_app(environ, start_response)
      File "pynba/wsgi/middleware.pyx", line 63, 
    in pynba.wsgi.middleware.PynbaMiddleware.__call__ (pynba/wsgi/middleware.c:1554)
      File "pynba/wsgi/middleware.pyx", line 64, 
    in pynba.wsgi.middleware.PynbaMiddleware.__call__ (pynba/wsgi/middleware.c:1510)
    TypeError: wsgi_app() takes exactly 3 arguments (2 given)

1

1 Answers

1
votes

Looks like pynba decorator is only designed to work on a normal function and not a method of a class.

You would need to do something like:

myapp = Flask()

@pynba.wsgi.monitor(('localhost', 30002))
def app(environ, start_response):
    return myapp(environ, start_response)

Writing a single decorator implementation that can work on both functions and methods of a class is non trivial. They should perhaps look at wrapt decorator library and use it to do it properly.

FWIW. If their middleware wrapper is:

then it also doesn't the job properly anyway. When a WSGI application is a generator all that will time is how long Python took to create the generator object. It will not time how long the WSGI application code took to run. Even on a normal function for the WSGI application, it will not time how long it took for the WSGI server to send the response and then subsequently call the close() of any iterable returned. It is therefore not at accurate representation of how long the WSGI application as a whole took.