I try to create a simple flask app:
from flask import Flask
app = Flask(__name__)
if __name__ == '__main__':
app.run()
but when I add the debug:
FLASK_APP = run.py
FLASK_ENV = development
FLASK_DEBUG = 1
I got the following error:
ValueError: signal only works in main thread
here the full stacktrace
FLASK_APP = run.py
FLASK_ENV = development
FLASK_DEBUG = 1
In folder c:/MyProjectPath/api
c:\MyProjectPath\api\venv\Scripts\python.exe -m flask run
* Serving Flask-SocketIO app "run.py"
* Forcing debug mode on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 283-122-745
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\appdata\local\programs\python\python37\Lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "c:\appdata\local\programs\python\python37\Lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "c:\MyProjectPath\api\venv\lib\site-packages\flask_socketio\cli.py", line 59, in run_server
return run_command()
File "c:\MyProjectPath\api\venv\lib\site-packages\click\core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "c:\MyProjectPath\api\venv\lib\site-packages\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "c:\MyProjectPath\api\venv\lib\site-packages\click\core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\MyProjectPath\api\venv\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "c:\MyProjectPath\api\venv\lib\site-packages\click\decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "c:\MyProjectPath\api\venv\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "c:\MyProjectPath\api\venv\lib\site-packages\flask\cli.py", line 771, in run_command
threaded=with_threads, ssl_context=cert)
File "c:\MyProjectPath\api\venv\lib\site-packages\werkzeug\serving.py", line 812, in run_simple
reloader_type)
File "c:\MyProjectPath\api\venv\lib\site-packages\werkzeug\_reloader.py", line 267, in run_with_reloader
signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
File "c:\appdata\local\programs\python\python37\Lib\signal.py", line 47, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
The problem you are facing has to do with a bug in the Flask-SocketIO package which replaces the flask run command. Due to this Flask-SocketIO is always used even if you don’t import it. There are several solutions:
Uninstall Flask-SocketIO
Do not use flask run but run the main file of your program
Disable debugging
Disable auto loading if debugging required flask run --no-reload
Reference to the Flask-SocketIO bug: issue 817
I solved the problem thanks to #AkshayKumar007 answer on github. That was the most convenient solution for me.
Hey guys, I was also facing the same problem. So to summarize, if
you're using socket-io, don't do flask run. First, add
if __name__ == "__main__":
socketio.run(app)
At the end of your application. To run it just do
python3 __init__.py
Hope it helped.
Related
I am trying to implement multiprocessing or threading in my flask __init__.py to implement a sub-process that will handle some back-end work for me. However, I can't seem to pass the application context to the sub-process, and exisitng libraries are focused on requests - I need this process to start running in parallel when flask is run, no later.
Here is my __init__.py code (excluding setup for irrelevant pages, I only use one implementation at a time ofc):
import os
from multiprocessing import Process
from threading import Thread
from flask_executor import Executor
from flask import Flask
from . import backend
def create_app():
app = Flask(__name__, instance_relative_config=True)
# Multiprocessing Implementation:
p = Process(target=backend.start)
p.start()
# Threading Implementation:
thread = Thread(target=backend.start)
thread.daemon = True
thread.start()
# Flask Executor Implementation:
executor = Executor(app)
executor.submit(backend.start)
return app
And here is my backend.py, called by the subprocess:
from datetime import datetime
from flask import g, request, session
from flaskr.db import log
def start(app=None):
print("\nBackend Started\n")
log("INFO","Backend Started")
while True:
pass
The backend code calls a logging function which works when called from a request inside my normal flask process.
My multiprocessing and threading implementation do not work, as I cannot pass the application context to the sub-process. Process(target=backend.start, args=app) or Thread(target=backend.start, args=app) gives me an error, TypeError: 'Flask' object is not iterable. I cannot add #with_appcontext flags to the start function, as it is not a request.
My Flask Executor passes the application context to the sub-process, but it cannot succeed either, as it is not called from a request:
Traceback (most recent call last):
File "c:\...\python\python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\...\python\python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\...\Python\Python39\Scripts\flask.exe\__main__.py", line 7, in <module>
File "c:\...\python\python39\lib\site-packages\flask\cli.py", line 988, in main
cli.main()
File "c:\...\python\python39\lib\site-packages\flask\cli.py", line 579, in main
return super().main(*args, **kwargs)
File "c:\...\python\python39\lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "c:\...\python\python39\lib\site-packages\click\core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\...\python\python39\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\...\python\python39\lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "c:\...\python\python39\lib\site-packages\click\decorators.py", line 84, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "c:\...\python\python39\lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "c:\...\python\python39\lib\site-packages\flask\cli.py", line 850, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
File "c:\...\python\python39\lib\site-packages\flask\cli.py", line 299, in __init__
self._load_unlocked()
File "c:\...\python\python39\lib\site-packages\flask\cli.py", line 333, in _load_unlocked
self._app = rv = self.loader()
File "c:\...\python\python39\lib\site-packages\flask\cli.py", line 389, in load_app
app = locate_app(import_name, name)
File "c:\...\python\python39\lib\site-packages\flask\cli.py", line 251, in locate_app
return find_best_app(module)
File "c:\...\python\python39\lib\site-packages\flask\cli.py", line 77, in find_best_app
app = app_factory()
File "C:\...\flaskr\__init__.py", line 51, in create_app
executor.submit(backend.start)
File "c:\...\python\python39\lib\site-packages\flask_executor\executor.py", line 162, in submit
fn = self._prepare_fn(fn)
File "c:\...\python\python39\lib\site-packages\flask_executor\executor.py", line 122, in _prepare_fn
fn = copy_current_request_context(fn)
File "c:\...\python\python39\lib\site-packages\flask\ctx.py", line 172, in copy_current_request_context
raise RuntimeError(
RuntimeError: This decorator can only be used when a request context is active, such as within a view function.
How can I implement this properly?
I found a solution to this issue. I added this code to my backend.py:
from flask import Blueprint
from threading import Thread
bp = Blueprint('backend', __name__)
def backend(app):
thread = Thread(target=start, args=(app,))
thread.daemon = True
thread.start()
I then added backend.backend(app) to my create_app() function in __init__.py, right before the end of my function. This will call my backend() function from backend.py and pass the application context, and this function starts my sub-process.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I just installed Python, pip, and flask.
Then I created a test file (hello.py):
from flask import Flask
app = Flask(_name_)
#app.route('/')
def index():
return 'Hello world!'
if __name__ == "__main__":
app.run()
when I try to run the file using
>set FLASK_APP=hello.py
>flask run
I get this error
Serving Flask app "hello.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
Traceback (most recent call last):
File "c:\users\ahmed\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\ahmed\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\ahmed\helloworld\env\Scripts\flask.exe\__main__.py", line 7, in <module>
File "c:\users\ahmed\helloworld\env\lib\site-packages\flask\cli.py", line 967, in main
cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
File "c:\users\ahmed\helloworld\env\lib\site-packages\flask\cli.py", line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "c:\users\ahmed\helloworld\env\lib\site-packages\click\core.py", line 782, in main
rv = self.invoke(ctx)
File "c:\users\ahmed\helloworld\env\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\ahmed\helloworld\env\lib\site-packages\click\core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\ahmed\helloworld\env\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "c:\users\ahmed\helloworld\env\lib\site-packages\click\decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "c:\users\ahmed\helloworld\env\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "c:\users\ahmed\helloworld\env\lib\site-packages\flask\cli.py", line 848, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
File "c:\users\ahmed\helloworld\env\lib\site-packages\flask\cli.py", line 305, in __init__
self._load_unlocked()
File "c:\users\ahmed\helloworld\env\lib\site-packages\flask\cli.py", line 330, in _load_unlocked
self._app = rv = self.loader()
File "c:\users\ahmed\helloworld\env\lib\site-packages\flask\cli.py", line 388, in load_app
app = locate_app(self, import_name, name)
File "c:\users\ahmed\helloworld\env\lib\site-packages\flask\cli.py", line 240, in locate_app
__import__(module_name)
File "C:\Users\ahmed\helloworld\hello.py", line 2, in <module>
app = Flask(_name_)
NameError: name '_name_' is not defined
The key is here
File "C:\Users\ahmed\helloworld\hello.py", line 2, in <module>
app = Flask(_name_)
NameError: name '_name_' is not defined
So, change
app = Flask(_name_)
to
app = Flask(__name__)
The reason for the double underscore is that in Python they have a special meaning. See Underscore vs Double underscore with variables and methods
and What is the meaning of single and double underscore before an object name?
The code you posted has also other issues. For example, in the last line you have no identation. Also, your formatting can be improved. Putting it together, your code might look like this.
from flask import Flask
app = Flask(__name__)
#app.route('/')
def index():
return 'Hello world!'
if __name__ == "__main__":
app.run()
I'm developing a personal website in Flask and I'm noticing something odd about the way the local server has been working for me.
When I do the following:
$ export FLASK_APP=run.py
$ flask run
This message is displayed:
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger pin code: 262-302-085
That's all well and good. But when I actually go to 127.0.0.1:5000, the server hangs and nothing ever happens. When I say 'hangs', I mean that the page stays blank but the loading icon indicates a successful connection, but the content of the site doesn't load. However, when I CTRL+C to close the script, then the website loads. Before doing so, it says the following:
^C * Serving Flask app "run"
Traceback (most recent call last):
File "/usr/local/bin/flask", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 507, in main
cli.main(args=args, prog_name=name)
File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 374, in main
return AppGroup.main(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 432, in run_command
use_debugger=debugger, threaded=with_threads)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 708, in run_simple
inner()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 670, in inner
fd=fd)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 564, in make_server
passthrough_errors, ssl_context, fd=fd)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 474, in __init__
socket.SOCK_STREAM)
socket.error: [Errno 9] Bad file descriptor
I thought this was an error or something, so I CTRL+C and then I get back to my command line. I refresh the page, expecting the website to go down, and it's still there! Not only that, but the terminal has seemingly resurrected the process and is displaying HTTP 2xx status codes in the terminal as I move around the site and refresh pages. Strange. So I killed both chromium and my terminal and the website STILL loaded! So I deleted my cache for the last hour, restarted my laptop, and it was STILL up! It kind of quietly failed after another ten minutes, but I really don't understand what's happening here.
Can anyone show this confused lad some mercy? Because it doesn't seem like I should have to kill the script before the website loads. Something feels off, aside from the obvious. Anyone know what I'm doing wrong? I've been able to reproduce the problem and this has happened more than once now.
Thank you.
EDIT: Fixed a sentence and clarified that the problem is reproducible.
I’m following a video from 2012 - Gevent-socketio, cross-framework real-time web live demo (https://www.youtube.com/watch?v=zhh_N5pmHBY)
I’m working on Ubuntu 15.04.
At 8 mins, in init.py he corrects config.add_renderer('.html', 'pyramid.mako_templating.renderer_factory') but after that I still can’t get it to work. The error I’m getting is below.
Any and all help would be greatly appreciated.
Thank you
(env)cloud#cloudnetwork:~/Code/python/3/moo/Moo$ pserve --reload development.ini
Starting subprocess with file monitor
Traceback (most recent call last):
File "/home/cloud/Code/python/3/moo/env/bin/pserve", line 9, in <module>
load_entry_point('pyramid==1.5.7', 'console_scripts', 'pserve')()
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 58, in main
return command.run()
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 328, in run
global_conf=vars)
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 363, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/paste/deploy/util.py", line 55, in fix_call
val = callable(*args, **kw)
File "/home/cloud/Code/python/3/moo/Moo/moo/__init__.py", line 10, in main
config.add_renderer('.html', 'pyramid.mako_templating.renderer_factory')
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/pyramid/util.py", line 528, in wrapper
result = wrapped(self, *arg, **kw)
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/pyramid/config/rendering.py", line 33, in add_renderer
factory = self.maybe_dotted(factory)
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/pyramid/config/__init__.py", line 825, in maybe_dotted
return self.name_resolver.maybe_resolve(dotted)
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/pyramid/path.py", line 320, in maybe_resolve
return self._resolve(dotted, package)
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/pyramid/path.py", line 327, in _resolve
return self._zope_dottedname_style(dotted, package)
File "/home/cloud/Code/python/3/moo/env/local/lib/python2.7/site-packages/pyramid/path.py", line 382, in _zope_dottedname_style
__import__(used)
ImportError: No module named mako_templating
The easiest way to register a new extension to be processed as a Mako template in Pyramid is as follows:
config.include('pyramid_mako')
config.add_mako_renderer('.html')
This will set up the renderer correctly.
Mako templating was removed from the Pyramid core framework, and thus pyramid.mako_templating.* no longer exists.
Depending on how you installed pyramid, you also need to install pyramid_mako, for instance by running pip install pyramid_mako. It's a separate module and is not a part of pyramid itself.
I have a Django project on an Ubuntu EC2 node, which I have been using to set up an asynchronous using Celery.
I am following How to list the queued items in celery? along with the docs, to experiment with celery at the command line.
I've been able to get a basic task working at the command line, using:
(env1)ubuntu#ip-172-31-22-65:~/projects/tp$ celery --app=myproject.celery:app worker --loglevel=INFO
However, if I run other celery commands like below I'm getting the following:
(env1)ubuntu#ip-172-31-22-65:~/projects/tp$ celery inspect ping
Traceback (most recent call last):
File "/home/ubuntu/.virtualenvs/env1/bin/celery", line 11, in <module>
sys.exit(main())
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/__main__.py", line 30, in main
main()
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 81, in main
cmd.execute_from_commandline(argv)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 769, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/base.py", line 307, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 761, in handle_argv
return self.execute(command, argv)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 693, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/base.py", line 311, in run_from_argv
sys.argv if argv is None else argv, command)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/base.py", line 373, in handle_argv
return self(*args, **options)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/base.py", line 270, in __call__
ret = self.run(*args, **kwargs)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 324, in run
return self.do_call_method(args, **kwargs)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 346, in do_call_method
callback=self.say_remote_command_reply)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/bin/celery.py", line 385, in call
return getattr(i, method)(*args)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/app/control.py", line 100, in ping
return self._request('ping')
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/app/control.py", line 71, in _request
timeout=self.timeout, reply=True,
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/celery/app/control.py", line 307, in broadcast
limit, callback, channel=channel,
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/kombu/pidbox.py", line 283, in _broadcast
chan = channel or self.connection.default_channel
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/kombu/connection.py", line 756, in default_channel
self.connection
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/kombu/connection.py", line 741, in connection
self._connection = self._establish_connection()
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/kombu/connection.py", line 696, in _establish_connection
conn = self.transport.establish_connection()
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/kombu/transport/pyamqp.py", line 112, in establish_connection
conn = self.Connection(**opts)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/amqp/connection.py", line 165, in __init__
self.transport = self.Transport(host, connect_timeout, ssl)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/amqp/connection.py", line 186, in Transport
return create_transport(host, connect_timeout, ssl)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/amqp/transport.py", line 299, in create_transport
return TCPTransport(host, connect_timeout)
File "/home/ubuntu/.virtualenvs/env1/lib/python3.4/site-packages/amqp/transport.py", line 95, in __init__
raise socket.error(last_err)
OSError: [Errno 111] Connection refused
The installed python packages:
(env1)ubuntu#ip-172-31-22-65:~/projects/tp$ pip freeze
amqp==1.4.6
anyjson==0.3.3
billiard==3.3.0.19
celery==3.1.17
Django==1.7.7
django-redis-cache==0.13.0
kombu==3.0.24
pytz==2015.2
redis==2.10.3
requests==2.6.0
uWSGI==2.0.10
/projects/tp/tp/celery.py
from __future__ import absolute_import
import os
import django
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tp.settings')
django.setup()
app = Celery('hello_django')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
also , in redis.conf:
# Specify the path for the unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
unixsocket /var/run/redis/redis.sock
unixsocketperm 777
tp.settings.py:
# CELERY SETTINGS
BROKER_URL = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': '/var/run/redis/redis.sock',
},
}
edit 2:
ubuntu#ip-172-31-22-65:~$ redis-cli ping
PONG
ubuntu#ip-172-31-22-65:~$ service redis-server status
redis-server is not running
edit 3:
(env1)ubuntu#ip-172-31-22-65:~/projects/tp$ redis-cli ping
PONG
(env1)ubuntu#ip-172-31-22-65:~/projects/tp$ sudo service redis-server start
Starting redis-server: failed
(env1)ubuntu#ip-172-31-22-65:~/projects/tp$ service redis-server status
redis-server is not running
What am I doing wrong?
Try this add it to project/__init__.py it should work, app is always imported so shared_task can use this app
from __future__ import absolute_import
from .celery import app as celery_app
__all__ = ('celery_app',)
I think you are using rabbitmq as queue.So check
sudo service rabbitmq-server status
if stop,
sudo service rabbitmq-server start