26👍
Another solution (taken from https://stackoverflow.com/a/17674248/39296) is to use –pidfile= (with no path) to not create a pidfile at all. Same effect as Siyu’s answer above.
10👍
I believe there is a pidfile in your project directory ./
then when you run the container, it’s mounted in.
(therefore RUN find . -type f -name "celerybeat.pid" -exec rm -f {} \;
had no effect).
You can use celery --pidfile=/opt/celeryd.pid
to specify a non mounted path so that it is not mirror on the host.
- [Django]-Project Name vs Application Name in Django
- [Django]-Error: can't start new thread
- [Django]-Django select max id
5👍
Although not professional in the slightest, I found adding:
celerybeat.pid
to my .dockerignore
file was what fixed said issues.
- [Django]-Django "login() takes exactly 1 argument (2 given)" error
- [Django]-Celery (Redis) results backend not working
- [Django]-Advantages to using URLField over TextField?
2👍
I had this error with Airflow when I run it with docker-compose.
If you don’t care about the current status of your Airflow, you can just delete airflow containers.
docker rm containerId
And after that, start the Airflow again:
docker-compose up
- [Django]-Django Rest Framework model serializer with out unique together validation
- [Django]-How to expose a property (virtual field) on a Django Model as a field in a TastyPie ModelResource
- [Django]-What is the easiest way to clear a database from the CLI with manage.py in Django?
2👍
Had the same issue as part of an Airflow setup (apache-airflow==2.3.4
, celery==5.2.7
), on Docker Compose:
ERROR: Pidfile (/airflow/airflow-worker.pid) already exists.
Seems we're already running? (pid: 1)
I tried to pass --pidfile
(actually --pid
under the Airflow umbrella) like so:
airflow celery worker --pid=
However this didn’t work, and a .pid
file was still being created. Maybe this is due to the additional Airflow layer.
Eventually, I figured that the original issue had to do with the Docker Compose restart policy (in my case, restart: always
). Once the worker had failed once, subsequent restarts would find the already existing .pid
file. This is because containers keep state on restart (see this or this).
A more permanent solution was to use a tmpfs, and point the .pid
file there:
# docker-compose.yml
worker:
image: {...}
tmpfs:
- /airflow-worker
entrypoint: airflow celery worker --pid=/airflow-worker/airflow-worker.pid
...
...
- [Django]-How can I serialize a queryset from an unrelated model as a nested serializer?
- [Django]-How to discriminate based on HTTP method in django urlpatterns
- [Django]-How to limit the queryset of an inline model in django admin
1👍
Other way, create a django command celery_kill.py
import shlex
import subprocess
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def handle(self, *args, **options):
kill_worker_cmd = 'pkill -9 celery'
subprocess.call(shlex.split(kill_worker_cmd))
docker-compose.yml :
celery:
build: ./src
restart: always
command: celery -A project worker -l info
volumes:
- ./src:/var/lib/celery/data/
depends_on:
- db
- redis
- app
celery-beat:
build: ./src
restart: always
command: celery -A project beat -l info --pidfile=/tmp/celeryd.pid
volumes:
- ./src:/var/lib/beat/data/
depends_on:
- db
- redis
- app
and Makefile:
run:
docker-compose up -d --force-recreate
docker-compose exec app python manage.py celery_kill
docker-compose restart
docker-compose exec app python manage.py migrate
- [Django]-How can I add a button into django admin change list view page
- [Django]-Foreignkey (user) in models
- [Django]-Django: Get an object form the DB, or 'None' if nothing matches
1👍
The reason of this error is docker container stopped without normal Celery stopping process.
The solution is simple. stop Celery before start.
Solution 1. write celery start command(ex> docker-entrypoint.sh, …) as follow
celery multi stopwait w1 -A myproject
&& rm -f /var/run/celery/w1.pid # remove stale pidfile
&& celery multi start w1 -A myproject-l info --pidfile=/var/run/celery/w1.pid
Solution 2. (not recommended)
always run "docker-compose down" before "docker-compose up".
- [Django]-Django.db.utils.ProgrammingError: relation "bot_trade" does not exist
- [Django]-Django templates – split string to array
- [Django]-How to access the local Django webserver from outside world