我有一个程序可以与 postgresql 服务器保持持久连接。假设由于网络问题导致连接被阻塞(可以通过关闭网络接口(interface)来模拟),使用 eventlet 调用查询的进程就会卡住。这也阻止了其他 eventlet 的执行。附加 gdb 表明进程在 psycopg2 C 代码中被阻止。我尝试了 postgresql TCP keepalives。但如果一旦连接丢失就调用查询,这也会失败。
有什么方法可以防止 eventlet 进入这种状态吗?有没有办法让 eventlet 摆脱这种状态。
GDB
#0 0x00002b4e7836be46 in poll () from /lib64/libc.so.6
#1 0x00002b4e835dec4f in ?? () from /usr/pgsql-9.0/lib/libpq.so.5
#2 0x00002b4e835ded50 in ?? () from /usr/pgsql-9.0/lib/libpq.so.5
#3 0x00002b4e835dd28e in PQgetResult () from /usr/pgsql-9.0/lib/libpq.so.5
#4 0x00002b4e833a4284 in psyco_exec_green (conn=0x21f42510, command=<value optimized out>) at psycopg/green.c:195
#5 0x00002b4e833a5387 in pq_execute_command_locked (conn=0x21f42510,
query=0x2b4e833b5de8 "BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED", pgres=0x7fff84c38448, error=0x7fff84c38440,
tstate=0x7fff84c38438) at psycopg/pqpath.c:342
#6 0x00002b4e833a58f7 in pq_begin_locked (conn=0x21f42510, pgres=0xffffffffffffffff, error=0xffffffffffffffff, tstate=0x0)
at psycopg/pqpath.c:424
#7 0x00002b4e833a59a0 in pq_execute (curs=0x1f487528, query=0x2248c894 "SELECT 1", async=0) at psycopg/pqpath.c:764
#8 0x00002b4e833ab15b in _psyco_curs_execute (self=0x1f487528, operation=0x0, vars=0x21ec9a80, async=0)
at psycopg/cursor_type.c:419
#9 0x00002b4e833ab7b1 in psyco_curs_execute (self=0x1f487528, args=<value optimized out>, kwargs=<value optimized out>)
at psycopg/cursor_type.c:475
最佳答案
抱歉回复晚了。
你使用了完整的猴子补丁吗?
如果错误仍然存在,请通过以下任一方式报告:
- https://bitbucket.org/which_linden/eventlet/issues/new
- https://github.com/eventlet/eventlet/issues/new
- 发送电子邮件至 eventletdev@lists.secondlife.com
请包含操作系统、Python、Eventlet 和 psycopg2 的版本。
关于python - Psycopg2 - Eventlet 连接挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11141175/