0

So I am making an app in Flask and I am using RabbitMQ as message broker and also backend Celery worker. I also use SocketIO in order to report back the celery worker status to the client. When I am running my app I get the following error: enter image description here

I appreciate if you let me know why do I get this error.

app.py

app = Flask(__name__)
app.config['SECRET_KEY'] = ''

app.config.update(
CELERY_BROKER_URL = 'amqp://localhost//',
CELERY_RESULT_BACKEND='amqp://localhost//'
)

socketio = SocketIO(app, message_queue='amqp://')
celery = make_celery(app)


@app.route('/')
def my_form():
    return render_template("form.html")

JavaScript

var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port );

make_celery module

def make_celery(app):
    celery = Celery(app.import_name, backend=app.config['CELERY_RESULT_BACKEND'],
                    broker=app.config['CELERY_BROKER_URL'])
    celery.conf.update(app.config)
    TaskBase = celery.Task
    class ContextTask(TaskBase):
        abstract = True
        def __call__(self, *args, **kwargs):
            with app.app_context():
                return TaskBase.__call__(self, *args, **kwargs)
    celery.Task = ContextTask
    return celery
Pooneh
  • 67
  • 2
  • 10

1 Answers1

2

Oops, the error message has been copy/pasted from another module, and I forgot to update it. The message should have read "Kombu requires a monkey patched socket library to work with gevent".

Basically this is saying that without monkey patching, gevent is going to block when socket operations are issued. See http://www.gevent.org/gevent.monkey.html for more details about this.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152
  • Thanks Miguel, monkey patching solved the issue. I am a bit confused though because I have made a simple app with Flask, Socket.io and also celery and it works perfectly without monkey patching. Here is the link to my simple app https://github.com/poonesh/Flask-SocketIO-Celery-example. So now, I am wondering why the simple app works? when we need to do monkey patching? – Pooneh May 26 '17 at 20:48
  • You need to monkey patch when you use a library that issues blocking operations. These are related to networking, threading, subprocesses, sleep, etc. If you don't monkey patch, those operations will block. You may not notice a problem if you have few clients, but with this is bad, as your application will freeze for the duration of these calls unless you monkey patch. – Miguel Grinberg May 27 '17 at 00:33
  • Thanks so much Miguel for your answer. – Pooneh May 27 '17 at 19:54