Answer the question
In order to leave comments, you need to log in
Why won't celery start?
Hello! There is a code:
from logging import debug
from flask import Flask
from flask_socketio import SocketIO
from celery import Celery
import threading
app = Flask("server", static_url_path="", static_folder='/')
app.config['SECRET_KEY'] = 'gjr39dkjn344_!67#'
app.config['broker_url'] = 'redis://127.0.0.1:6379/0'
app.config['result_backend'] = 'redis://127.0.0.1:6379/0'
def make_celery(app):
celery = Celery(
"server",
backend=app.config['broker_url'],
broker=app.config['result_backend']
)
celery.conf.update(app.config)
class ContextTask(celery.Task):
def __call__(self, *args, **kwargs):
with app.app_context():
return self.run(*args, **kwargs)
celery.Task = ContextTask
return celery
celery = make_celery(app)
@celery.task()
async def my_background_task():
f = open("text.txt", "w")
f.write("fsdsdf")
return "sss"
@app.route("/")
async def main():
task = my_background_task.delay()<code></code>
print(task)
return "sss"
celery --app server.celery worker --loglevel info
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question