Created
December 1, 2020 18:14
-
-
Save ngoue/6068c34ae03846ec766d2c31d813fd6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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