我有一个程序可以保持与 postgresql 服务器的持久连接。假设由于网络问题导致连接被阻塞(可以通过关闭网络接口来模拟),使用 eventlet 调用查询的进程卡住了。这也阻止了其他小事件的执行。附加 gdb 表明进程在 psycopg2 C 代码中被阻止。我试过postgresql TCP keepalives。但是,如果在连接丢失后立即调用查询,这也会失败。
有什么办法可以防止 eventlet 进入这种状态?有什么办法可以让 eventlet 脱离这种状态。
广发银行
#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