Psycopg2 - Eventlet连接挂起

时间:2012-06-21 15:09:40

标签: python psycopg2 eventlet

我有一个与postgresql服务器保持持久连接的程序。假设由于网络问题导致连接被阻塞(可以通过关闭网络接口来模拟),使用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

1 个答案:

答案 0 :(得分:1)

很抱歉迟到的回复。

你是否使用完整的猴子补丁?

如果错误仍然存​​在,请通过以下任何方式报告:

请包含OS,Python,Eventlet和psycopg2的版本。