django Celery 的几个异常

最近开始整合推送相关的内容,由于之前已经集成了 uniadmin 的相关功能,所以继承起来不算太麻烦。至于推送相关的内容可能会单独写一篇,也可不能不写了。嘎嘎。

在推送的时候需要调用 uni 的云函数,而这个函数的调用是需要耗时间的,所以最好能够异步进行处理。好久没做异步相关的内容了,又查了下相关的资料,发现还是基于 celery 是最简单的。不过一切都部署好运行的时候出现了几个问题:

1.changelist must be an iterable of select.kevent objects

运行命令:celery -A dayima_backend worker -l debug -P eventlet

 dayima_backend % celery  -A dayima_backend worker  -l debug -P eventlet
[2024-02-20 17:24:56,726: DEBUG/MainProcess] | Worker: Preparing bootsteps.
[2024-02-20 17:24:56,727: DEBUG/MainProcess] | Worker: Building graph...
[2024-02-20 17:24:56,727: DEBUG/MainProcess] | Worker: New boot order: {Beat, StateDB, Timer, Hub, Pool, Autoscaler, Consumer}
[2024-02-20 17:24:56,731: DEBUG/MainProcess] | Consumer: Preparing bootsteps.
[2024-02-20 17:24:56,731: DEBUG/MainProcess] | Consumer: Building graph...
[2024-02-20 17:24:56,736: DEBUG/MainProcess] | Consumer: New boot order: {Connection, Events, Mingle, Tasks, Control, Heart, Agent, Gossip, event loop}
 
 -------------- celery@obabydeMacBook-Pro.local v5.3.6 (emerald-rush)
--- ***** ----- 
-- ******* ---- macOS-14.2.1-arm64-arm-64bit 2024-02-20 17:24:56
- *** --- * --- 
- ** ---------- [config]
- ** ---------- .> app:         dayima_backend:0x107dfcac0
- ** ---------- .> transport:   redis://127.0.0.1:6379/1
- ** ---------- .> results:     redis://127.0.0.1:6379/2
- *** --- * --- .> concurrency: 8 (eventlet)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery
                

[tasks]
  . celery.accumulate
  . celery.backend_cleanup
  . celery.chain
  . celery.chord
  . celery.chord_unlock
  . celery.chunks
  . celery.group
  . celery.map
  . celery.starmap

[2024-02-20 17:24:56,754: DEBUG/MainProcess] | Worker: Starting Pool
[2024-02-20 17:24:56,754: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:24:56,755: DEBUG/MainProcess] | Worker: Starting Consumer
[2024-02-20 17:24:56,755: DEBUG/MainProcess] | Consumer: Starting Connection
[2024-02-20 17:24:56,760: WARNING/MainProcess] /Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py:507: CPendingDeprecationWarning: The broker_connection_retry configuration setting will no longer determine
whether broker connection retries are made during startup in Celery 6.0 and above.
If you wish to retain the existing behavior for retrying connections on startup,
you should set broker_connection_retry_on_startup to True.
  warnings.warn(

[2024-02-20 17:24:56,761: CRITICAL/MainProcess] Unrecoverable error: TypeError('changelist must be an iterable of select.kevent objects')
Traceback (most recent call last):
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/kombu/transport/virtual/base.py", line 951, in create_channel
    return self._avail_channels.pop()
IndexError: pop from empty list

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/worker/worker.py", line 202, in start
    self.blueprint.start(self)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/bootsteps.py", line 116, in start
    step.start(parent)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/bootsteps.py", line 365, in start
    return self.obj.start()
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 340, in start
    blueprint.start(self)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/bootsteps.py", line 116, in start
    step.start(parent)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/worker/consumer/connection.py", line 21, in start
    c.connection = c.connect()
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 469, in connect
    conn = self.connection_for_read(heartbeat=self.amqheartbeat)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 475, in connection_for_read
    return self.ensure_connected(
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 526, in ensure_connected
    conn = conn.ensure_connection(
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/kombu/connection.py", line 406, in ensure_connection
    self._ensure_connection(*args, **kwargs)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/kombu/connection.py", line 459, in _ensure_connection
    return retry_over_time(
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/kombu/utils/functional.py", line 318, in retry_over_time
    return fun(*args, **kwargs)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/kombu/connection.py", line 934, in _connection_factory
    self._connection = self._establish_connection()
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/kombu/connection.py", line 860, in _establish_connection
    conn = self.transport.establish_connection()
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/kombu/transport/virtual/base.py", line 975, in establish_connection
    self._avail_channels.append(self.create_channel(self))
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/kombu/transport/virtual/base.py", line 953, in create_channel
    channel = self.Channel(connection)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/kombu/transport/redis.py", line 744, in __init__
    self.client.ping()
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/redis/commands/core.py", line 1216, in ping
    return self.execute_command("PING", **kwargs)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/redis/client.py", line 533, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/redis/connection.py", line 1086, in get_connection
    connection.connect()
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/redis/connection.py", line 264, in connect
    sock = self.retry.call_with_retry(
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/redis/retry.py", line 46, in call_with_retry
    return do()
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/redis/connection.py", line 265, in <lambda>
    lambda: self._connect(), lambda error: self.disconnect(error)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/redis/connection.py", line 615, in _connect
    sock.connect(socket_address)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/eventlet/greenio/base.py", line 248, in connect
    self._trampoline(fd, write=True)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/eventlet/greenio/base.py", line 206, in _trampoline
    return trampoline(fd, read=read, write=write, timeout=timeout,
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/eventlet/hubs/__init__.py", line 153, in trampoline
    listener = hub.add(hub.WRITE, fileno, current.switch, current.throw, mark_as_closed)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/eventlet/hubs/kqueue.py", line 52, in add
    self._control([event], 0, 0)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/eventlet/hubs/kqueue.py", line 38, in _control
    return self.kqueue.control(events, max_events, timeout)
TypeError: changelist must be an iterable of select.kevent objects
[2024-02-20 17:24:56,784: DEBUG/MainProcess] | Worker: Closing Pool...
[2024-02-20 17:24:56,784: DEBUG/MainProcess] | Worker: Closing Consumer...
[2024-02-20 17:24:56,784: DEBUG/MainProcess] | Worker: Stopping Consumer...
[2024-02-20 17:24:56,784: DEBUG/MainProcess] | Worker: Stopping Pool...
[2024-02-20 17:24:56,784: DEBUG/MainProcess] | Consumer: Shutdown Gossip...
[2024-02-20 17:24:56,784: DEBUG/MainProcess] | Consumer: Shutdown Heart...
[2024-02-20 17:24:56,784: DEBUG/MainProcess] | Consumer: Shutdown Control...
[2024-02-20 17:24:56,784: DEBUG/MainProcess] | Consumer: Shutdown Tasks...
[2024-02-20 17:24:56,784: DEBUG/MainProcess] | Consumer: Shutdown Events...
[2024-02-20 17:24:56,784: DEBUG/MainProcess] | Consumer: Shutdown Connection...

这个错误是-P eventlet导致的,可以去掉最后的这个-P eventlet参数。

2.Cannot connect to redis://127.0.0.1:6379/1: Error 61 connecting to 127.0.0.1:6379. Connection refused

 dayima_backend % celery  -A dayima_backend worker  -l debug            
[2024-02-20 17:26:29,112: DEBUG/MainProcess] | Worker: Preparing bootsteps.
[2024-02-20 17:26:29,114: DEBUG/MainProcess] | Worker: Building graph...
[2024-02-20 17:26:29,114: DEBUG/MainProcess] | Worker: New boot order: {Timer, Hub, Pool, Autoscaler, StateDB, Beat, Consumer}
[2024-02-20 17:26:29,117: DEBUG/MainProcess] | Consumer: Preparing bootsteps.
[2024-02-20 17:26:29,117: DEBUG/MainProcess] | Consumer: Building graph...
[2024-02-20 17:26:29,122: DEBUG/MainProcess] | Consumer: New boot order: {Connection, Events, Mingle, Gossip, Agent, Tasks, Control, Heart, event loop}
 
 -------------- celery@obabydeMacBook-Pro.local v5.3.6 (emerald-rush)
--- ***** ----- 
-- ******* ---- macOS-14.2.1-arm64-arm-64bit 2024-02-20 17:26:29
- *** --- * --- 
- ** ---------- [config]
- ** ---------- .> app:         dayima_backend:0x107074640
- ** ---------- .> transport:   redis://127.0.0.1:6379/1
- ** ---------- .> results:     redis://127.0.0.1:6379/2
- *** --- * --- .> concurrency: 8 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery
                

[tasks]
  . celery.accumulate
  . celery.backend_cleanup
  . celery.chain
  . celery.chord
  . celery.chord_unlock
  . celery.chunks
  . celery.group
  . celery.map
  . celery.starmap

[2024-02-20 17:26:29,134: DEBUG/MainProcess] | Worker: Starting Hub
[2024-02-20 17:26:29,135: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:26:29,135: DEBUG/MainProcess] | Worker: Starting Pool
[2024-02-20 17:26:29,171: DEBUG/ForkPoolWorker-1] Using selector: KqueueSelector
[2024-02-20 17:26:29,206: DEBUG/ForkPoolWorker-2] Using selector: KqueueSelector
[2024-02-20 17:26:29,251: DEBUG/ForkPoolWorker-3] Using selector: KqueueSelector
[2024-02-20 17:26:29,284: DEBUG/ForkPoolWorker-4] Using selector: KqueueSelector
[2024-02-20 17:26:29,315: DEBUG/ForkPoolWorker-5] Using selector: KqueueSelector
[2024-02-20 17:26:29,350: DEBUG/ForkPoolWorker-6] Using selector: KqueueSelector
[2024-02-20 17:26:29,393: DEBUG/ForkPoolWorker-7] Using selector: KqueueSelector
[2024-02-20 17:26:29,440: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:26:29,441: DEBUG/MainProcess] | Worker: Starting Consumer
[2024-02-20 17:26:29,441: DEBUG/MainProcess] | Consumer: Starting Connection
[2024-02-20 17:26:29,444: DEBUG/ForkPoolWorker-8] Using selector: KqueueSelector
[2024-02-20 17:26:29,452: WARNING/MainProcess] /Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py:507: CPendingDeprecationWarning: The broker_connection_retry configuration setting will no longer determine
whether broker connection retries are made during startup in Celery 6.0 and above.
If you wish to retain the existing behavior for retrying connections on startup,
you should set broker_connection_retry_on_startup to True.
  warnings.warn(

[2024-02-20 17:26:29,454: ERROR/MainProcess] consumer: Cannot connect to redis://127.0.0.1:6379/1: Error 61 connecting to 127.0.0.1:6379. Connection refused..
Trying again in 2.00 seconds... (1/100)

[2024-02-20 17:26:31,467: ERROR/MainProcess] consumer: Cannot connect to redis://127.0.0.1:6379/1: Error 61 connecting to 127.0.0.1:6379. Connection refused..
Trying again in 4.00 seconds... (2/100)

[2024-02-20 17:26:35,486: ERROR/MainProcess] consumer: Cannot connect to redis://127.0.0.1:6379/1: Error 61 connecting to 127.0.0.1:6379. Connection refused..
Trying again in 6.00 seconds... (3/100)

^C

redis 服务导致的错误,无法连接 redis,查看服务是否启动

3.you should set broker_connection_retry_on_startup to True.

dayima_backend % celery  -A dayima_backend worker  -l debug 
[2024-02-20 17:26:54,887: DEBUG/MainProcess] | Worker: Preparing bootsteps.
[2024-02-20 17:26:54,888: DEBUG/MainProcess] | Worker: Building graph...
[2024-02-20 17:26:54,888: DEBUG/MainProcess] | Worker: New boot order: {StateDB, Beat, Timer, Hub, Pool, Autoscaler, Consumer}
[2024-02-20 17:26:54,892: DEBUG/MainProcess] | Consumer: Preparing bootsteps.
[2024-02-20 17:26:54,892: DEBUG/MainProcess] | Consumer: Building graph...
[2024-02-20 17:26:54,897: DEBUG/MainProcess] | Consumer: New boot order: {Connection, Events, Mingle, Tasks, Control, Agent, Gossip, Heart, event loop}
 
 -------------- celery@obabydeMacBook-Pro.local v5.3.6 (emerald-rush)
--- ***** ----- 
-- ******* ---- macOS-14.2.1-arm64-arm-64bit 2024-02-20 17:26:54
- *** --- * --- 
- ** ---------- [config]
- ** ---------- .> app:         dayima_backend:0x103468640
- ** ---------- .> transport:   redis://127.0.0.1:6379/1
- ** ---------- .> results:     redis://127.0.0.1:6379/2
- *** --- * --- .> concurrency: 8 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery
                

[tasks]
  . celery.accumulate
  . celery.backend_cleanup
  . celery.chain
  . celery.chord
  . celery.chord_unlock
  . celery.chunks
  . celery.group
  . celery.map
  . celery.starmap

[2024-02-20 17:26:54,909: DEBUG/MainProcess] | Worker: Starting Hub
[2024-02-20 17:26:54,909: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:26:54,909: DEBUG/MainProcess] | Worker: Starting Pool
[2024-02-20 17:26:54,945: DEBUG/ForkPoolWorker-1] Using selector: KqueueSelector
[2024-02-20 17:26:54,978: DEBUG/ForkPoolWorker-2] Using selector: KqueueSelector
[2024-02-20 17:26:55,023: DEBUG/ForkPoolWorker-3] Using selector: KqueueSelector
[2024-02-20 17:26:55,067: DEBUG/ForkPoolWorker-4] Using selector: KqueueSelector
[2024-02-20 17:26:55,105: DEBUG/ForkPoolWorker-5] Using selector: KqueueSelector
[2024-02-20 17:26:55,149: DEBUG/ForkPoolWorker-6] Using selector: KqueueSelector
[2024-02-20 17:26:55,184: DEBUG/ForkPoolWorker-7] Using selector: KqueueSelector
[2024-02-20 17:26:55,210: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:26:55,210: DEBUG/MainProcess] | Worker: Starting Consumer
[2024-02-20 17:26:55,211: DEBUG/MainProcess] | Consumer: Starting Connection
[2024-02-20 17:26:55,214: DEBUG/ForkPoolWorker-8] Using selector: KqueueSelector
[2024-02-20 17:26:55,219: WARNING/MainProcess] /Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py:507: CPendingDeprecationWarning: The broker_connection_retry configuration setting will no longer determine
whether broker connection retries are made during startup in Celery 6.0 and above.
If you wish to retain the existing behavior for retrying connections on startup,
you should set broker_connection_retry_on_startup to True.
  warnings.warn(

[2024-02-20 17:26:55,224: INFO/MainProcess] Connected to redis://127.0.0.1:6379/1
[2024-02-20 17:26:55,225: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:26:55,225: DEBUG/MainProcess] | Consumer: Starting Events
[2024-02-20 17:26:55,225: WARNING/MainProcess] /Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py:507: CPendingDeprecationWarning: The broker_connection_retry configuration setting will no longer determine
whether broker connection retries are made during startup in Celery 6.0 and above.
If you wish to retain the existing behavior for retrying connections on startup,
you should set broker_connection_retry_on_startup to True.
  warnings.warn(

[2024-02-20 17:26:55,226: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:26:55,226: DEBUG/MainProcess] | Consumer: Starting Mingle
[2024-02-20 17:26:55,227: INFO/MainProcess] mingle: searching for neighbors
[2024-02-20 17:26:56,236: INFO/MainProcess] mingle: all alone
[2024-02-20 17:26:56,236: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:26:56,236: DEBUG/MainProcess] | Consumer: Starting Tasks
[2024-02-20 17:26:56,243: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:26:56,243: DEBUG/MainProcess] | Consumer: Starting Control
[2024-02-20 17:26:56,247: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:26:56,247: DEBUG/MainProcess] | Consumer: Starting Gossip
[2024-02-20 17:26:56,251: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:26:56,251: DEBUG/MainProcess] | Consumer: Starting Heart
[2024-02-20 17:26:56,253: DEBUG/MainProcess] ^-- substep ok
[2024-02-20 17:26:56,253: DEBUG/MainProcess] | Consumer: Starting event loop
[2024-02-20 17:26:56,253: DEBUG/MainProcess] | Worker: Hub.register Pool...
[2024-02-20 17:26:56,254: INFO/MainProcess] celery@obabydeMacBook-Pro.local ready.
[2024-02-20 17:26:56,254: DEBUG/MainProcess] basic.qos: prefetch_count->32
^C
worker: Hitting Ctrl+C again will terminate all running tasks!

这个错误网上的解决方案能搜到一堆,但是基本都是在 配置文件中添加:

CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True

broker_connection_retry_on_startup=True

事实证明,这个方法对我来说无效,需要在创建示例的地方(Celery.py 第一个字母为大写,后续说这个问题)添加参数BROKER_CONNECTION_RETRY_ON_STARTUP=True:

celery_app = Celery('dayima_backend',BROKER_CONNECTION_RETRY_ON_STARTUP=True)
celery_app.config_from_object('django.conf:settings')

4.循环引用错误:ImportError: cannot import name ‘Celery’ from partially initialized module ‘celery’ (most likely due to a circular import) 

/Users/obaby/PycharmProjects/dayima_backend/venv/bin/Python /Users/obaby/PycharmProjects/dayima_backend/dayima_backend/cron.py 
Traceback (most recent call last):
  File "/Users/obaby/PycharmProjects/dayima_backend/dayima_backend/cron.py", line 16, in <module>
    django.setup()
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/django/__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/obaby/PycharmProjects/dayima_backend/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/obaby/PycharmProjects/dayima_backend/dayima_backend/__init__.py", line 1, in <module>
    from .celery import celery_app
  File "/Users/obaby/PycharmProjects/dayima_backend/dayima_backend/celery.py", line 3, in <module>
    from celery import Celery
  File "/Users/obaby/PycharmProjects/dayima_backend/dayima_backend/celery.py", line 3, in <module>
    from celery import Celery
ImportError: cannot import name 'Celery' from partially initialized module 'celery' (most likely due to a circular import) (/Users/obaby/PycharmProjects/dayima_backend/dayima_backend/celery.py)

进程已结束,退出代码为 1

如果按照网上的某些教程抄,可能就会出现这个问题,出问题的地方在于,这个小写的文件名和导入的 celery 库冲突了。解决也简单,把项目下的文件名首字母改为大写即可。

服务启动可以改用 gunicorn:

gunicorn dayima_backend.wsgi:application --workers=4 --worker-class=gevent --bind=0.0.0.0:8000
[2024-02-20 17:57:20 +0800] [33898] [INFO] Starting gunicorn 21.2.0
[2024-02-20 17:57:20 +0800] [33898] [INFO] Listening at: http://0.0.0.0:8000 (33898)
[2024-02-20 17:57:20 +0800] [33898] [INFO] Using worker: gevent
[2024-02-20 17:57:20 +0800] [33901] [INFO] Booting worker with pid: 33901
[2024-02-20 17:57:20 +0800] [33902] [INFO] Booting worker with pid: 33902
[2024-02-20 17:57:20 +0800] [33903] [INFO] Booting worker with pid: 33903
[2024-02-20 17:57:20 +0800] [33905] [INFO] Booting worker with pid: 33905
[2024-02-20 17:57:23 +0800] [33898] [INFO] Handling signal: winch

 

☆版权☆

* 网站名称:obaby@mars
* 网址:https://h4ck.org.cn/
* 个性:https://oba.by/
* 本文标题: 《django Celery 的几个异常》
* 本文链接:https://h4ck.org.cn/2024/02/15510
* 短链接:https://oba.by/?p=15510
* 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。


You may also like

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注