gevent and flask rest_plus

177 views
Skip to first unread message

Mor Dabastany

unread,
Mar 18, 2019, 11:19:37 AM3/18/19
to gevent: coroutine-based Python network library
Hi,
I didn't find any example for creating a flask-restplus app with using gevent.

can someone refer me to example? 

Kevin Tewouda

unread,
Mar 19, 2019, 12:38:26 AM3/19/19
to gevent: coroutine-based Python network library
Hi Mor,
The basic idea is to monkeypatch standard libraries before creating your flask app.For example  I just took the restplus example and adapted it to flask context

from gevent import monkey, pywsgi

from flask import Flask
from flask_restplus import Resource, Api

app = Flask(__name__)
api = Api(app)

@api.route('/hello')
class HelloWorld(Resource):
    def get(self):
        return {'hello': 'world'}

if __name__ == '__main__':
http_server = pywsgi.WSGIServer(('', 5000), app)
http_server.serve_forever()

Hope it will help you :)

Best regards.

Reply all
Reply to author
Forward
0 new messages