Psycopg2 db connection hangs on lost network connection
问题 Problem description I'm using psycopg2 to connect to my PostgreSQL database on a remote host. I open a connection and wait for requests, then for each request I run queries on the connection and return data. But when the network connection is lost after the connection is already open the next db query hangs and I have to kill the program manually. Details: it hangs for at least 2 hours (I couldn't wait longer) the "network down" situation is actually VPN going down (db host is accesible only