python - Flask gevent threads are stuck on kafka consumer
问题描述
We have a flask app, deploying using gunicorn in gevent worker mode. The app itself listen to few REST apis but also have a kafka consumer (using confluent client) it listen to. When we deploy the app, kafka consumer work as expected but when submitting REST request to the app, they are not being handled by the app.
Seem like the app threads are stuck on the kafka consumer. If we remove the consumer code the app work as expected.
Any advice?
解决方案
The issue was that the way we use kafka consumer is in a "while True"
while True:
msg = self.client.poll(1.0)
if msg is None:
continue
if msg.error():
print("Consumer error: {}".format(msg.error()))
continue
self.handle_msg(msg.value())
Which cause the gevent
to be stuck on it and not switching to other threads.
The solution was to add a sleep command in the consumer loop which free the thread to handle REST requests as well
推荐阅读
- vhdl - 为什么我的七段显示器只显示 0?
- javascript - 如何使用javascript获取已删除项目的值
- c# - 实现类以处理实时数据
- javascript - 修复不和谐 !avatar 命令的代码
- python - 将两个不同列表中的值顺序分配给python数据框中的列
- visual-studio - 让 Premake 生成一个引用现有 .props 文件的 vcxproj 文件
- c - malloc:从内存中获取信息
- angular - Docker 上的 Jenkins 开始在 Docker 上构建 Angular 应用程序
- javascript - 从大括号外读取时,变量“未声明”
- authentication - 仅 OTP 身份验证