Issue 1:
Checklist

I have read the relevant section in the

contribution guide

on reporting bugs.

I have checked the issues list

for similar or identical bug reports.

I have checked the pull requests list

for existing proposed fixes.

I have checked the commit log

to find out if the bug was already fixed in the master branch.

I have included all related issues and possible duplicate issues

in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

I have included the output of celery -A proj report in the issue.

(if you are not able to do this, then at least specify the Celery

version affected).

I have verified that the issue exists against the master branch of Celery.

I have included the contents of pip freeze in the issue.

I have included all the versions of all the external dependencies required

to reproduce this bug.

Optional Debugging Information

I have tried reproducing the issue on more than one Python version

and/or implementation.

I have tried reproducing the issue on more than one message broker and/or

result backend.

I have tried reproducing the issue on more than one version of the message

broker and/or result backend.

I have tried reproducing the issue on more than one operating system.

I have tried reproducing the issue on more than one workers pool.

I have tried reproducing the issue with autoscaling, retries,

ETA/Countdown & rate limits disabled.

I have tried reproducing the issue after downgrading

and/or upgrading Celery and its dependencies.

Related Issues and Possible Duplicates

Related Issues

None

Possible Duplicates

None

Environment & Settings

Celery version: 3.1.25 (Cipater)

celery report Output:

CELERY_ACCEPT_CONTENT: ['pickle', 'json', 'msgpack', 'yaml']
CELERY_RESULT_BACKEND: 'djcelery.backends.database:DatabaseBackend'
BROKER_URL: 'redis://redis:6379/1'

Steps to Reproduce

Required Dependencies

Minimal Python Version: 3.6.8

Minimal Celery Version: 3.1.25

Minimal Kombu Version: N/A or Unknown

Minimal Broker Version: redis 2.10.6

Minimal Result Backend Version: N/A or Unknown

Minimal OS and/or Kernel Version: N/A or Unknown

Minimal Broker Client Version: N/A or Unknown

Minimal Result Backend Client Version: N/A or Unknown

Python Packages

pip freeze Output:

amqp==1.4.9
anyjson==0.3.3
asgi-redis==1.4.3
asgiref==1.1.2
asn1crypto==0.24.0
attrs==19.1.0
autobahn==19.7.1
Automat==0.7.0
beautifulsoup4==4.6.3
billiard==3.3.0.23
blinker==1.4
celery==3.1.25
certifi==2019.6.16
cffi==1.11.5
channels==1.1.8
chardet==3.0.4
Click==7.0
clinner==1.12.3
colorlog==3.2.0
constantly==15.1.0
coreapi==2.3.3
coreschema==0.0.4
cryptography==2.4.2
daphne==1.3.0
ddt==1.2.1
decorator==4.4.0
Django==1.11.12
django-accredible==0.5.0
django-activity-stream==0.6.5
django-anonymizer===0.5.0.16-bw
django-appconf==1.0.2
django-autocomplete-light==3.2.9
django-autoslug==1.9.3
django-backupdb==0.7.0
django-bootstrap-breadcrumbs==0.8.2
django-bootstrap-pagination==1.6.2
django-bootstrap3==9.0.0
django-braces==1.11.0
django-celery==3.2.1
django-channels-presence==0.0.9
django-cors-headers==3.0.2
django-exo-mentions==1.0.0
django-extensions==2.1.6
django-extra-fields==0.9
django-filter==1.0.4
django-form-utils==1.0.3
django-generic-m2m==0.3.1
django-guardian==1.4.9
django-markdown==0.8.4
django-model-utils==3.0.0
django-multiselectfield==0.1.8
django-password-reset==0.9
django-ratings-models==0.1.10
django-redis-sessions==0.6.1
django-rest-params==1.0.2
django-rest-swagger==2.1.2
django-sizefield==0.9.1
django-stats-redis==0.1.1
django-storages==1.6.3
django-tagulous==0.14.0
django-timezone-field==2.1
django-timezone-utils==0.11
django-typeform-feedback==0.1.5
django-versionfield2==0.5.0
djangorestframework==3.9.4
djangorestframework-camel-case==1.0.3
djangorestframework-jwt==1.11.0
drf-nested-routers==0.90.0
drf-openapi==1.3.0
exo-changelog==0.1.3
factory-boy==2.7.0
fake-factory==0.5.7
Faker==0.7.7
filestack-python==2.3.1
flatbuffers==1.11
future==0.17.1
gitdb==0.6.4
gitdb2==2.0.5
GitPython==2.1.12
graphene==1.4.1
graphene-django==1.3
graphql-core==1.1
graphql-relay==0.4.5
gunicorn==19.9.0
health-check==3.4.1
hyperlink==19.0.0
icalendar==4.0.1
idna==2.7
incremental==17.5.0
inflection==0.3.1
ipython==6.1.0
ipython-genutils==0.2.0
iso8601==0.1.12
itypes==1.1.0
jedi==0.14.1
Jinja2==2.10.1
kombu==3.0.37
lib-exo-messages==1.3.2
lxml==4.2.5
Markdown==3.1.1
MarkupSafe==1.1.1
meld3==1.0.2
mimeparse==0.1.3
msgpack-python==0.5.6
olefile==0.43
openapi-codec==1.3.2
parso==0.5.1
pexpect==4.7.0
pickleshare==0.7.5
pilkit==2.0
Pillow==5.3.0
promise==2.2.1
prompt-toolkit==1.0.16
psycopg2==2.7.4
psycopg2-binary==2.7.4
ptyprocess==0.6.0
pyaccredible==0.6.0
pyasn1==0.4.5
pyasn1-modules==0.2.5
pycairo==1.16.3
pycparser==2.19
pycrypto==2.6.1
pycurl==7.43.0.2
Pygments==2.4.2
pygobject==3.28.2
PyHamcrest==1.9.0
PyJWT==1.7.1
pyOpenSSL==18.0.0
python-dateutil==2.7.5
pytz==2019.1
PyYAML==3.12
redis==2.10.6
requests==2.20.0
requests-toolbelt==0.9.1
sentry-sdk==0.10.2
service-identity==18.1.0
setproctitle==1.1.10
simplegeneric==0.8.1
simplejson==3.16.0
singledispatch==3.4.0.3
six==1.12.0
smmap==0.9.0
smmap2==2.0.5
supervisor==4.0.4
trafaret==1.2.0
traitlets==4.3.2
Twisted==19.2.1
txaio==18.8.1
uritemplate==3.0.0
urllib3==1.24.3
wcwidth==0.1.7
XlsxWriter==1.1.8
zope.interface==4.6.0

Other Dependencies

Minimally Reproducible Test Case

docker exec service sh
./manage.py shell

from example.celery import debug_task
from datetime import datetime
debug_task.apply_async(eta=datetime(2019,10,10,10))

exit container
docker restart containerID

Expected Behavior

After docker container restarts should have:

celery@18346e3912df: OK
* {'eta': '2019-10-10T10:00:00+00:00', 'priority': 6, 'request': {'id': '306f5dec-0bcd-4894-a2da-4a1234e3c10d', 'name': 'exolever.celery.debug_task', 'args': '[]', 'kwargs': '{}', 'hostname': 'celery@18346e3912df', 'time_start': None, 'acknowledged': False, 'delivery_info': {'exchange': 'celery', 'routing_key': 'celery', 'priority': 0, 'redelivered': None}, 'worker_pid': None}}

Actual Behavior

-> celery@18346e3912df: OK
- empty -

Issue 2:
Checklist

I have checked the issues list

for similar or identical bug reports.

I have checked the pull requests list

for existing proposed fixes.

I have checked the commit log

to find out if the bug was already fixed in the master branch.

I have included all related issues and possible duplicate issues in this issue

(If there are none, check this box anyway).

Related Issues and Possible Duplicates

I've not found any documentation on embedding Celery Workers into my Python program. Everything so far has been extending workers to add functionality when the workers start or stop. The closest thing I found was the Py.Test celery/contrib/testing/app.py code but I couldn't figure out how, the setup I've got is similar.

Related Issues

None

Possible Duplicates

None

Description

I'm trying to embed Celery into a CherryPy server. I'm not looking for a lot of concurrency. So, a single process multi-threaded application is desirable for long running tasks that won't return in a reasonable time for web applications.

It seems like both frameworks have good extending documentation with very similar usage patterns. So the reverse could be asked as well, how do I embed a CherryPy server into Celery?

https://docs.cherrypy.org/en/latest/extend.html

https://docs.celeryproject.org/en/stable/userguide/extending.html

Here's the code I have so far.

from threading import Thread
from cherrypy.process import plugins
from celery.bin import worker as celery_worker
from .config import get_config
from .tasks import celery_app

def run_celery_worker():
"""Run the main solo worker."""
worker = celery_worker.worker(app=celery_app)
options = {
'broker': get_config().get('celery', 'broker_url'),
'loglevel': 'INFO',
'traceback': True,
'pool': 'eventlet'
}
return worker.run(**options)

class CeleryThreadPlugin(plugins.SimplePlugin):
def start(self):
self.bus.log('Starting up Celery worker')
self.celery_thread = Thread(target=run_celery_worker)
self.celery_thread.start()

def stop(self):
self.bus.log('Stopping down Celery worker')
celery_app.loader.shutdown_worker()
sleep(10)
# The Celery worker.run() isn't returning
self.bus.log('Celery worker is {}'.format(self.celery_thread.isAlive()))
self.celery_thread.join()
self.bus.log('Celery worker joined')

I'm using memory:/// for my broker_url similar to the Py.Test integration. The problem is shutdown is not clean. The main script runs and brings up both CherryPy and Celery, when I hit Ctrl-C CherryPy handles the shutdown sequence. The worker.run() method doesn't seem to return to stop the worker thread.

I've tried various ways to issue the worker shutdown and none of them seem to make worker.run() return.

Suggestions

It would be nice to have some good documentation on how to embed Celery properly in another application. CherryPy does have similar docs and I've followed them to success embedding CherryPy into specialized Python applications.

Some things to consider:

Is it okay for Celery workers to be managed from child Python thread (not main)?

What would the API be for that usage?