Django 芹菜运行时错误:populate()不是';t重入

Django 芹菜运行时错误:populate()不是';t重入,django,runtime-error,celery,populate,Django,Runtime Error,Celery,Populate,我可以从CLI启动worker,但不能从主管启动worker。我试着在不同的用户下运行它,它对一些用户有效,而对其他用户无效。它总是像根一样工作。 所以我认为这可能与一些环境变量或权限有关 但是哈哈 项目地点正在确定中 /opt/data/project,并将其设置为chown apache:apache-R/opt/data/project 主管3.4.4 django 1.11.3 芹菜4.2.1 我做了很多标准配置 cat/opt/project/CORE/CORE/芹菜.py from

我可以从CLI启动worker,但不能从主管启动worker。我试着在不同的用户下运行它,它对一些用户有效,而对其他用户无效。它总是像根一样工作。 所以我认为这可能与一些环境变量或权限有关

但是哈哈

项目地点正在确定中 /opt/data/project,并将其设置为chown apache:apache-R/opt/data/project

主管3.4.4 django 1.11.3 芹菜4.2.1

我做了很多标准配置

cat/opt/project/CORE/CORE/芹菜.py

from __future__ import absolute_import, unicode_literals
import os
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', 'CORE.settings')

app = Celery('CORE')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))
cat/opt/project/CORE/CORE/init.py

from __future__ import absolute_import, unicode_literals

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

__all__ = ('celery_app',)
cat/etc/supervisor/conf.d/celeryd.conf

; ==================================
;  Celery worker
; ==================================
; For additional options see http://supervisord.org/configuration.html#program-x-section-settings

[program:celery]

environment=
    PATH="/opt/data/project/bin:${PATH}",
    LD_LIBRARY_PATH="/opt/data/project/lib"
user=apache; change user nobody , root
directory=/opt/data/project/CORE
command=/opt/data/project/bin/celery worker -A CORE --loglevel=INFO --pidfile="/var/run/celery/celery.pid"
numprocs=1

; ***START OPTIONs***
autostart=true      ; Set it to "true" if you want supervisord to start service/script on system boot.
autorestart=true    ; Set it to "true" if you want supervisord to start service/script if it stops unexpectedly.
startsecs=10        ; The total number of seconds which the program needs to stay running after a startup to consider the start successful.
startretries=3      ; The number of retries to do before giving up trying to run service/script.
; ***LOGS***
stdout_logfile=/var/log/supervisor/%(program_name)s.log     ; The file where the errors will be written.
stderr_logfile=/var/log/supervisor/%(program_name)s_err.log ; The file where the regular outputs will be written.
;stderr_logfile_maxbytes=50     ; The maximum number of bytes that may be consumed by stderr_logfile before it is rotated
;stdout_logfile_maxbytes=50     ; The maximum number of bytes that may be consumed by stdout_logfile before it is rotated

; ***STOP OPTIONs***
stopasgroup=true

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

; ***PRIORITY***
; Set Celery priority higher than default (999)
; so, if rabbitmq is supervised, it will start first.
priority=1001        ; 999 -RabbitMq, 1000 -Redis, 1001 -Celery worker, 1002 -celery flower, etc...
发行

RuntimeError: populate() isn't reentrant
Traceback (most recent call last):
  File "/opt/data/project/bin/celery", line 18, in <module>
    sys.exit(main())
  File "/opt/data/project/lib/python2.7/site-packages/celery/__main__.py", line 16, in main
    _main()
  File "/opt/data/project/lib/python2.7/site-packages/celery/bin/celery.py", line 322, in main
    cmd.execute_from_commandline(argv)
  File "/opt/data/project/lib/python2.7/site-packages/celery/bin/celery.py", line 496, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/opt/data/project/lib/python2.7/site-packages/celery/bin/base.py", line 275, in execute_from_commandline
    return self.handle_argv(self.prog_name, argv[1:])
  File "/opt/data/project/lib/python2.7/site-packages/celery/bin/celery.py", line 488, in handle_argv
    return self.execute(command, argv)
  File "/opt/data/project/lib/python2.7/site-packages/celery/bin/celery.py", line 420, in execute
    ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
  File "/opt/data/project/lib/python2.7/site-packages/celery/bin/worker.py", line 223, in run_from_argv
    return self(*args, **options)
  File "/opt/data/project/lib/python2.7/site-packages/celery/bin/base.py", line 238, in __call__
    ret = self.run(*args, **kwargs)
  File "/opt/data/project/lib/python2.7/site-packages/celery/bin/worker.py", line 257, in run
    **kwargs)
  File "/opt/data/project/lib/python2.7/site-packages/celery/worker/worker.py", line 96, in __init__
    self.app.loader.init_worker()
  File "/opt/data/project/lib/python2.7/site-packages/celery/loaders/base.py", line 119, in init_worker
    self.import_default_modules()
  File "/opt/data/project/lib/python2.7/site-packages/celery/loaders/base.py", line 112, in import_default_modules
    raise response
RuntimeError: populate() isn't reentrant
vi/opt/data/project/lib/python2.7/site-packages/芹菜/loaders/base.py

   def import_default_modules(self):
        responses = signals.import_modules.send(sender=self.app)
        # Prior to this point loggers are not yet set up properly, need to
        #   check responses manually and reraised exceptions if any, otherwise
        #   they'll be silenced, making it incredibly difficult to debug.
        for _, response in responses:
            file = open("/var/run/celery/testfile.txt","ab")
            file.write("TEST: " + str(_) + ' ' + str(dir(response)) + '\n')
            file.close()
            if isinstance(response, Exception):
                raise response
        return [self.import_task_module(m) for m in self.default_modules]
cat/var/run/芹菜/testfile.txt

SUPERVISOR_SERVER_URL=unix:///tmp/supervisor.sock
SUPERVISOR_ENABLED=1
SUPERVISOR_PROCESS_NAME=celery
SUPERVISOR_GROUP_NAME=celery
_=/opt/data/project/bin/supervisord
SHLVL=2
LANG=en_US.UTF-8
PWD=/
PATH=/opt/data/project/bin:${PATH}
LD_LIBRARY_PATH=/opt/data/project/lib

TEST: <bound method ?.on_import_modules of <celery.fixups.django.DjangoFixup object at 0x7f2ac72ccb50>> ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
TEST: <promise@0x7f2ac7383df8 --> <bound method Celery._autodiscover_tasks of <Celery CORE at 0x7f2ac72cca50>>> ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
SUPERVISOR\u SERVER\u URL=unix:///tmp/supervisor.sock
已启用管理器\u=1
主管\流程\名称=芹菜
主管组名称=芹菜
_=/opt/data/project/bin/supervisord
SHLVL=2
LANG=en_US.UTF-8
PWD=/
PATH=/opt/data/project/bin:${PATH}
LD_LIBRARY_PATH=/opt/data/project/lib
“UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU钩子
“UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUsshook_u']
上面的输出是当一切正常时,当我切换到不正常的用户时,我得到了完全相同的环境变量,但缺少“测试”部分。我在“raiseresponse”之前在base.py中写入文件,所以应该有一些内容,但实际上什么都没有

SUPERVISOR_SERVER_URL=unix:///tmp/supervisor.sock
SUPERVISOR_ENABLED=1
SUPERVISOR_PROCESS_NAME=celery
SUPERVISOR_GROUP_NAME=celery
_=/opt/data/project/bin/supervisord
SHLVL=2
LANG=en_US.UTF-8
PWD=/
PATH=/opt/data/project/bin:${PATH}
LD_LIBRARY_PATH=/opt/data/project/lib

TEST: <bound method ?.on_import_modules of <celery.fixups.django.DjangoFixup object at 0x7f2ac72ccb50>> ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
TEST: <promise@0x7f2ac7383df8 --> <bound method Celery._autodiscover_tasks of <Celery CORE at 0x7f2ac72cca50>>> ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']