You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot access Django ORM in worker when using python3+eventlet #2829
And when I try to access my database from within a worker task, (Model.objects.stuff()), I get the following error:
django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 140124131096384 and th
The thing is, I've found through the internet that I should explicitly monkey_patch my project to make things work. The suggestion was to have the code below in my manage.py:
As documentation mentions no further configuration for using eventlet besides informing that you want to use it to the worker, and I'm not quite sure what EVENTLET_NOPATCH and the event.debug.hub... stuff do, I'm here to ask what is a good way to make celery+django+models+eventlet work.
By the way, my worker is invoked like this, from upstart:
If you use manage.py then the patching happens to late to patch everything, so you will have mysterious problems.
The solution is to move into using the new Celery+Django project layout, using celery -A proj worker instead of manage.py, or patching manage.py as you write there.
It's not necessary to set the EVENTLET_NOPATCH environment variable, as there is no danger
in calling monkey_patch multiple times.
Activity
ask commentedon Dec 12, 2015
If you use manage.py then the patching happens to late to patch everything, so you will have mysterious problems.
The solution is to move into using the new Celery+Django project layout, using
celery -A proj workerinstead ofmanage.py, or patchingmanage.pyas you write there.It's not necessary to set the EVENTLET_NOPATCH environment variable, as there is no danger
in calling monkey_patch multiple times.