Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not use it with celery. #2

Closed
adityaU opened this issue Feb 12, 2014 · 3 comments
Closed

can not use it with celery. #2

adityaU opened this issue Feb 12, 2014 · 3 comments

Comments

@adityaU
Copy link

adityaU commented Feb 12, 2014

from flask.ext.socketio import SocketIO, emit
from flask import Flask
from celery import Celery



def make_celery(app):
    celery = Celery(app.import_name, 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


app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
app.config.update(
    CELERY_BROKER_URL='redis://localhost:6379/0',
    CELERY_RESULT_BACKEND='redis://localhost:6379/0'
)
# socketio = SocketIO(app)
celery = make_celery(app)

celery hangs with:

...
[tasks]
  . celery.backend_cleanup
  . celery.chain
  . celery.chord
  . celery.chord_unlock
  . celery.chunks
  . celery.group
  . celery.map
  . celery.starmap
  . server.add_together

[2014-02-13 01:51:27,420: DEBUG/MainProcess] | Worker: Starting Pool
@adityaU
Copy link
Author

adityaU commented Feb 12, 2014

forgot to mention.

logger.addHandler(app.logger)

doesn't seem to be correct. you should not add logger to handlers
output in the my last comment is without it.

@adityaU
Copy link
Author

adityaU commented Feb 12, 2014

Thanks To celery guys!
It is working now. needed to add '--pool=gevent' to celery command.
Still. Need to fix logger.handlers.

for handler in app.logger.handlers:  logger.addHandler(handler)

in SocketIO class' init_app method.
I really don't want to fork the repo for a small thing.

@miguelgrinberg
Copy link
Owner

I actually did not intend to leave that snippet of logging in the released version, it is a quick hack that allowed me to redirect the logging while developing but that is really something the extension shouldn't mess with. I'll just remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants