- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个使用 gevent
的 celery worker 执行 HTTP 请求并使用页面源添加另一个 celery 任务的池。
我正在使用 Django,RabbitMQ 作为代理,Redis 作为 celery 结果后端,Celery 4.1.0。
任务有ignore_result=True
但我经常收到此错误 ConcurrentObjectUseError: This socket is already used by another greenlet: <bound method Waiter.switch of <gevent.hub.Waiter...>
我看到它与Redis连接有关。
我不知道如何解决这个问题。这或多或少是任务的逻辑。我还尝试在调用 process_task.apply_async
时使用信号量但它没有用。
from gevent.lock import BoundedSemaphore
sem = BoundedSemaphore(1)
@app.task(ignore_result=True, queue='request_queue')
def request_task(url, *args, **kwargs):
# make the request
req = requests.get(url)
request = {
'status_code': req.status_code,
'content': req.text,
'headers': dict(req.headers),
'encoding': req.encoding
}
with sem:
process_task.apply_async(kwargs={'url': url, 'request': request})
print(f'Done - {url}')
这是堆栈跟踪:
cancel_wait_ex: [Errno 9] File descriptor was closed in another greenlet
File "redis/connection.py", line 543, in send_packed_command
self._sock.sendall(item)
File "gevent/_socket3.py", line 424, in sendall
data_sent += self.send(data_memory[data_sent:], flags, timeout=timeleft)
File "gevent/_socket3.py", line 394, in send
self._wait(self._write_event)
File "gevent/_socket3.py", line 156, in _wait
self.hub.wait(watcher)
File "gevent/hub.py", line 651, in wait
result = waiter.get()
File "gevent/hub.py", line 898, in get
return self.hub.switch()
File "gevent/hub.py", line 630, in switch
return RawGreenlet.switch(self)
ConnectionError: Error 9 while writing to socket. File descriptor was closed in another greenlet.
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 556, in send_packed_command
(errno, errmsg))
OSError: [Errno 9] Bad file descriptor
File "redis/connection.py", line 126, in _read_from_socket
data = self._sock.recv(socket_read_size)
File "gevent/_socket3.py", line 332, in recv
return _socket.socket.recv(self._sock, *args)
ConnectionError: Error while reading from socket: (9, 'Bad file descriptor')
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 538, in send_packed_command
self.connect()
File "redis/connection.py", line 446, in connect
self.on_connect()
File "redis/connection.py", line 520, in on_connect
if nativestr(self.read_response()) != 'OK':
File "redis/connection.py", line 577, in read_response
response = self._parser.read_response()
File "redis/connection.py", line 238, in read_response
response = self._buffer.readline()
File "redis/connection.py", line 168, in readline
self._read_from_socket()
File "redis/connection.py", line 143, in _read_from_socket
(e.args,))
BlockingIOError: [Errno 11] Resource temporarily unavailable
File "gevent/_socket3.py", line 390, in send
return _socket.socket.send(self._sock, data, flags)
OSError: [Errno 9] Bad file descriptor
File "redis/connection.py", line 543, in send_packed_command
self._sock.sendall(item)
File "gevent/_socket3.py", line 424, in sendall
data_sent += self.send(data_memory[data_sent:], flags, timeout=timeleft)
File "gevent/_socket3.py", line 396, in send
return _socket.socket.send(self._sock, data, flags)
ConnectionError: Error 9 while writing to socket. Bad file descriptor.
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 556, in send_packed_command
(errno, errmsg))
BlockingIOError: [Errno 11] Resource temporarily unavailable
File "gevent/_socket3.py", line 390, in send
return _socket.socket.send(self._sock, data, flags)
OSError: [Errno 9] Bad file descriptor
File "redis/connection.py", line 543, in send_packed_command
self._sock.sendall(item)
File "gevent/_socket3.py", line 424, in sendall
data_sent += self.send(data_memory[data_sent:], flags, timeout=timeleft)
File "gevent/_socket3.py", line 396, in send
return _socket.socket.send(self._sock, data, flags)
ConnectionError: Error 9 while writing to socket. Bad file descriptor.
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 556, in send_packed_command
(errno, errmsg))
BlockingIOError: [Errno 11] Resource temporarily unavailable
File "gevent/_socket3.py", line 390, in send
return _socket.socket.send(self._sock, data, flags)
ConcurrentObjectUseError: This socket is already used by another greenlet: <bound method Waiter.switch of <gevent.hub.Waiter object at 0x7f271b53dea0>>
File "celery/app/trace.py", line 374, in trace_task
R = retval = fun(*args, **kwargs)
File "celery/app/trace.py", line 629, in __protected_call__
return self.run(*args, **kwargs)
File "drones/tasks.py", line 330, in blue_drone_request_task
blue_drone_process_task.apply_async(kwargs={'targetpage': targetpage, 'request': request})
File "celery/app/task.py", line 536, in apply_async
**options
File "celery/app/base.py", line 736, in send_task
self.backend.on_task_call(P, task_id)
File "celery/backends/redis.py", line 189, in on_task_call
self.result_consumer.consume_from(task_id)
File "celery/backends/redis.py", line 76, in consume_from
self._consume_from(task_id)
File "celery/backends/redis.py", line 82, in _consume_from
self._pubsub.subscribe(key)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 538, in send_packed_command
self.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 538, in send_packed_command
self.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2172, in _execute
connection.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2172, in _execute
connection.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2172, in _execute
connection.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 538, in send_packed_command
self.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 538, in send_packed_command
self.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2172, in _execute
connection.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2172, in _execute
connection.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 538, in send_packed_command
self.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2172, in _execute
connection.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 538, in send_packed_command
self.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2172, in _execute
connection.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2172, in _execute
connection.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 538, in send_packed_command
self.connect()
File "redis/connection.py", line 455, in connect
callback(self)
File "redis/client.py", line 2120, in on_connect
self.subscribe(**channels)
File "redis/client.py", line 2229, in subscribe
ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
File "redis/client.py", line 2161, in execute_command
self._execute(connection, connection.send_command, *args)
File "redis/client.py", line 2165, in _execute
return command(*args)
File "redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "redis/connection.py", line 543, in send_packed_command
self._sock.sendall(item)
File "gevent/_socket3.py", line 424, in sendall
data_sent += self.send(data_memory[data_sent:], flags, timeout=timeleft)
File "gevent/_socket3.py", line 394, in send
self._wait(self._write_event)
File "gevent/_socket3.py", line 150, in _wait
raise _socketcommon.ConcurrentObjectUseError('This socket is already used by another greenlet: %r' % (watcher.callback, ))
最佳答案
我不确定这是否是正确答案,但通过设置 CELERY_RESULT_BACKEND = None,我不再看到此错误。
希望对您有所帮助。
仅供引用 此错误仅在使用 gevent 池时发生。我尝试过的 Celery 版本:3.1、4.2.1。
关于python - Celery Gevent 池 - ConcurrentObjectUseError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49447720/
当我运行此命令进行 celery 节拍时。 [2013-06-27 02:17:05,936: INFO/MainProcess] Celerybeat: Starting... [2013-06-2
我需要构建一个处理两种类型任务的系统。一种类型可以创建更多自身或另一种类型的任务。将有很少的 worker (2-3)和只有一个主机。最重要的要求是系统应该优雅地处理重新启动:即在重新启动时,正在进行
我们使用 Celery 4.2.1 和 Redis,并为我们的任务设置了全局软超时和硬超时。我们所有的自定义任务都设计为保持在限制范围内,但每天内置任务 backend_cleanup 任务最终都会因
我知道这违背了使用 Celery 的全部目的,但是是否有一个函数会阻塞直到结果返回? 所以我可以调用 actual_result = MyTask.dont_delay(some_arg="foo")
我们使用 Celery 4.2.1 和 Redis,并为我们的任务设置了全局软超时和硬超时。我们所有的自定义任务都设计为保持在限制范围内,但每天内置任务 backend_cleanup 任务最终都会因
我知道这违背了使用 Celery 的全部目的,但是是否有一个函数会阻塞直到结果返回? 所以我可以调用 actual_result = MyTask.dont_delay(some_arg="foo")
我计划使用 celery 作为我的项目的任务管理组件。它几乎具有我的项目所需的所有功能。我将有一组可以独立执行或按指定顺序执行的任务。在顺序任务中,我希望能够在中间任务之一失败时执行清理/回滚。我想知
它是运行 Celery 的实际处理器还是另一个进程?在花中,我可以在工作池中看到多个进程吗?这两者之间有什么区别? 最佳答案 当您运行 celery worker 时,它会创建一个父进程来管理正在运行
我有一个名为 ShippingApp 的项目,我按照步骤设置了 celery worker。我将 celery 3.1.26.post2 与 python3.7 一起使用,当我想启动 Celery W
尽我所能,我无法杀死这些 celery worker 。 我跑: celery --app=my_app._celery:app status 我看到我有3个(我不明白为什么3个 worker = 2
我在 docker 容器中运行了 celery ,我想检查选项 CELERY_TASK_RESULT_EXPIRES = '3600' 是否已应用。 我尝试使用 celery inspect conf
我使用 celery.chord(...) 创建一组任务和一个方法,该方法在组中的所有任务完成后被调用。 我使用 amqp 结果后端(但我想切换到 memcached)。 我的 worker 每秒钟一
我正在寻找一些关于将任务生成的列表映射到 celery 中的另一个任务的最佳方法的建议。 假设我有一个名为 parse 的任务,它解析 PDF 文档并输出页面列表。然后,每个页面都需要单独传递给另一个
这不是关于如何捕获 celery worker 日志的问题。有什么方法可以捕获生产者上的 celery 日志记录。我想要的是捕获当我调用 task.delay(...) 或 task.apply_as
我正在使用以下版本: 花==0.9.3 celery ==4.3.0 这为我提供了包含多个列的任务页面的以下显示: 每次我进入这个页面时,我最终都会重新排列页面,使列的顺序不同,并将行的顺序更改为降序
我想完成这样的事情: results = [] for i in range(N): data = generate_data_slowly() res = tasks.process
我想运行一个由beat 调度的复杂任务。让我们假设定义了默认的 add/mul 任务。 @app.on_after_configure.connect def setup_periodic_tasks
我有一个应用程序,其中包含 celery worker 。当我部署这将杀死那些正在运行的进程。 所以任务将开始,但永远不会完成,并且在部署完成时不会重新启动。 避免此问题并在部署完成后重新启动这些任务
我正在开始使用 Celery 进行 Django 项目。出于本地开发目的,我根据这些说明使用 djcelery 和 djkombu(数据库传输)进行了设置 http://ask.github.com/
如何配置 celery 在任务失败时发送电子邮件警报? 例如,我希望 Celery 在 3 个以上的任务失败或 10 个以上的任务被重试时通知我。 是否可以使用 celery 或实用程序(例如花),或
我是一名优秀的程序员,十分优秀!