Skip to content

Instantly share code, notes, and snippets.

@ngoue
Created December 1, 2020 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngoue/6068c34ae03846ec766d2c31d813fd6c to your computer and use it in GitHub Desktop.
Save ngoue/6068c34ae03846ec766d2c31d813fd6c to your computer and use it in GitHub Desktop.
from time import sleep
import psycopg2
CONN_INFO = {
'host': '',
'port': 5432,
'dbname': '',
'user': '',
'password': '',
}
def log(*args):
print('\x1b[1K\r', end='')
print(*args, end='', flush=True)
def query():
conn = psycopg2.connect(**CONN_INFO)
cursor = conn.cursor()
cursor.execute('SELECT * FROM people;')
cursor.fetchall()
log('Queries operating normally')
def test():
try:
while True:
try:
query()
except psycopg2.errors.Error as e:
log('Error running query')
sleep(1)
except KeyboardInterrupt:
print('\nexiting test')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment