芹菜+芹菜工人的问题

  • 本文关键字:芹菜 问题 python celery
  • 更新时间 :
  • 英文 :


所以我对芹菜完全陌生,我一直在努力遵循文档中的教程,但遇到了问题。当我无法获得芹菜工人的结果时,问题就出现了。这是我在一个名为tasks.py的文件中的代码(我有rabbitMQ设置(:

from celery import Celery
app = Celery('tasks', backend='rpc://', broker='amqp://localhost')

@app.task
def adding(x, y):
return x + y

我用以下命令运行一个工作程序:

celery -A tasks worker --loglevel=info

运行该命令后,这是输出代码:


-------------- celery@Tims-PC v4.4.6 (cliffs)
--- ***** -----
-- ******* ---- Windows-10-10.0.19041-SP0 2020-08-01 00:38:28
- *** --- * ---
- ** ---------- [config]
- ** ---------- .> app:         tasks:0x43bbcd0
- ** ---------- .> transport:   amqp://guest:**@localhost:5672//
- ** ---------- .> results:     rpc://
- *** --- * --- .> concurrency: 12 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery           exchange=celery(direct) key=celery

[tasks]
. tasks.adding
[2020-08-01 00:38:28,270: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672//
[2020-08-01 00:38:28,406: INFO/MainProcess] mingle: searching for neighbors
[2020-08-01 00:38:28,804: INFO/SpawnPoolWorker-3] child process 14948 calling self.run()
[2020-08-01 00:38:28,811: INFO/SpawnPoolWorker-8] child process 4396 calling self.run()
[2020-08-01 00:38:28,813: INFO/SpawnPoolWorker-5] child process 488 calling self.run()
[2020-08-01 00:38:28,814: INFO/SpawnPoolWorker-7] child process 15252 calling self.run()
[2020-08-01 00:38:28,814: INFO/SpawnPoolWorker-1] child process 9816 calling self.run()
[2020-08-01 00:38:28,817: INFO/SpawnPoolWorker-4] child process 21044 calling self.run()
[2020-08-01 00:38:28,822: INFO/SpawnPoolWorker-6] child process 1052 calling self.run()
[2020-08-01 00:38:28,826: INFO/SpawnPoolWorker-11] child process 20656 calling self.run()
[2020-08-01 00:38:28,832: INFO/SpawnPoolWorker-2] child process 21240 calling self.run()
[2020-08-01 00:38:28,839: INFO/SpawnPoolWorker-9] child process 3036 calling self.run()
[2020-08-01 00:38:28,847: INFO/SpawnPoolWorker-10] child process 13052 calling self.run()
[2020-08-01 00:38:28,847: INFO/SpawnPoolWorker-12] child process 17780 calling self.run()
[2020-08-01 00:38:29,333: INFO/SpawnPoolWorker-13] child process 10320 calling self.run()
[2020-08-01 00:38:29,333: INFO/SpawnPoolWorker-14] child process 22176 calling self.run()
[2020-08-01 00:38:29,335: INFO/SpawnPoolWorker-15] child process 13656 calling self.run()
[2020-08-01 00:38:29,664: INFO/MainProcess] mingle: all alone
[2020-08-01 00:38:29,671: WARNING/MainProcess] c:userstimothee legrospycharmprojectscelerytestingvenvlibsite-packageskombupidbox.py:74: UserWarning: A node named celery@Tims-P
C is already using this process mailbox!
Maybe you forgot to shutdown the other node or did not do so properly?
Or if you meant to start multiple nodes on the same host please make sure
you give each node a unique node name!
warnings.warn(W_PIDBOX_IN_USE.format(node=self))
[2020-08-01 00:38:29,677: INFO/MainProcess] celery@Tims-PC ready.

一旦到了这里,我就无法键入任何内容,ctrl-c只打印出我应该再次按ctrl-c退出的内容,但当我这样做时,什么都不会发生。这不是我的主要问题。我的主要问题是,当我使用python控制台使用工作程序时,如下所示:

from tasks import adding
result = adding.delay(3, 4)

该代码返回AsyncResult,但发生了两件事:

  1. 原始终端窗口中没有更新任何信息来指示任何工作人员处理了任务,并且
  2. 当我尝试访问这样的结果时:
result.get()

python控制台冻结了,我再也不能键入或做任何事情了。为了重新获得对python控制台的控制,我必须ctrl-c,这会引发socket.timeout错误。

有人有办法解决我的问题吗?到处的教程都显示,当任务运行时,最初启动工作程序的原始终端窗口应该会更新,result.get((应该返回任务返回的数据。

因为我可以在您的工作控制台-上看到这一行

task events: OFF (enable -E to monitor tasks in this worker)

我想您应该尝试使用-E选项来运行celery-worker,如下所示:

celery -A tasks worker --loglevel=info -E

我不太确定,但你可以试一试。


您也可以在这里参考我的答案-用于存储您的任务结果:https://stackoverflow.com/a/62387375/6490744

相关内容

  • 没有找到相关文章

最新更新