问题描述
我遇到了与使用 gunicorn eventlet 服务器在 SigTerm 处理程序中使用活动 I/O 连接相关的问题。
server.py
def exit_with_grace(*args):
conn = get_redis_connection()
conn.set('exited_gracefully',True)
signal.signal(signal.SIGTERM,exit_with_grace)
我也尝试启动 celery 任务(使用 amqp 代理),但我所有的想法都失败了。当我使用 python server.py
在调试模式下启动服务器时,它运行良好。 Gunicorn+ eventlet 不允许在 sigterm 处理程序中连接到 redis,导致出现以下错误:
Traceback (most recent call last):
File "/project/handlers/socketio/redis_context_backend.py",line 256,in publish_pattern
return conn.publish(pattern,serialized)
File "/project/venv/lib/python3.6/site-packages/redis/client.py",line 3098,in publish
return self.execute_command('PUBLISH',channel,message)
File "/project/venv/lib/python3.6/site-packages/redis/client.py",line 898,in execute_command
conn = self.connection or pool.get_connection(command_name,**options)
File "/project/venv/lib/python3.6/site-packages/redis/connection.py",line 1192,in get_connection
connection.connect()
File "/project/venv/lib/python3.6/site-packages/redis/connection.py",line 559,in connect
sock = self._connect()
File "/project/venv/lib/python3.6/site-packages/redis/connection.py",line 603,in _connect
sock.connect(socket_address)
File "/project/venv/lib/python3.6/site-packages/eventlet/greenio/base.py",line 250,in connect
self._trampoline(fd,write=True)
File "/project/venv/lib/python3.6/site-packages/eventlet/greenio/base.py",line 210,in _trampoline
mark_as_closed=self._mark_as_closed)
File "/project/venv/lib/python3.6/site-packages/eventlet/hubs/__init__.py",line 142,in trampoline
assert hub.greenlet is not current,'do not call blocking functions from the mainloop'
Gunicorn 命令:
gunicorn --worker-class eventlet -w 1 server:ws --reload -b localhost:5001
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)