I'm running some tasks which are actually taking more time than five minutes and I've already established connection with NeonDB(Postgres) as it's serverless when i use cursor.query it's throwing me error
import osfrom psycopg_pool import ConnectionPoolfrom time import sleep# Create a connection pooldbPool = ConnectionPool( conninfo="postgresurl?sslmode=require", min_size=2, max_size=10,)def dbConnection(): ''' Function to create a connection and cursor ''' con = dbPool.getconn() cursor = con.cursor() return con, cursor# Establishing DB Connectioncon, cursor = dbConnection()print("Sleep has started")sleep(630)print("Sleep has ended")query = f"""UPDATE kPost SET score=0 WHERE postId='01HS94YD7K0JPN72ZMMK7WADAH';"""cursor.execute(query)print("Query executed")con.commit()print("Query committed")con.close()print("Connection closed")
import osfrom psycopg_pool import ConnectionPoolfrom time import sleep# Create a connection pooldbPool = ConnectionPool( conninfo="postgresurl?sslmode=require", min_size=2, max_size=10,)def dbConnection(): ''' Function to create a connection and cursor ''' con = dbPool.getconn() cursor = con.cursor() return con, cursor# Establishing DB Connectioncon, cursor = dbConnection()print("Sleep has started")sleep(630)print("Sleep has ended")query = f"""UPDATE kPost SET score=0 WHERE postId='01HS94YD7K0JPN72ZMMK7WADAH';"""cursor.execute(query)print("Query executed")con.commit()print("Query committed")con.close()print("Connection closed")
Output is as below:
Sleep has startedSleep has endedTraceback (most recent call last): File "/Users/dharmesh/Documents/.kBackend/kContainers/dbConnectionDisconnection/dbConnection.py", line 28, in <module> cursor.execute(query) File "/Users/dharmesh/Documents/.kBackend/kContainers/venv/lib/python3.11/site-packages/psycopg/cursor.py", line 732, in execute raise ex.with_traceback(None)psycopg.OperationalError: consuming input failed: SSL SYSCALL error: EOF detected
Sleep has startedSleep has endedTraceback (most recent call last): File "/Users/dharmesh/Documents/.kBackend/kContainers/dbConnectionDisconnection/dbConnection.py", line 28, in <module> cursor.execute(query) File "/Users/dharmesh/Documents/.kBackend/kContainers/venv/lib/python3.11/site-packages/psycopg/cursor.py", line 732, in execute raise ex.with_traceback(None)psycopg.OperationalError: consuming input failed: SSL SYSCALL error: EOF detected
It took almost 16m, Even though sleep is for just five and a half minute, As cursor.query() might be trying and trying for connection