From 4a7e2c1602ed82aabd7d04953067ba49cb1cebff Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 10 Mar 2022 08:55:26 +0300 Subject: Use context manager with database connection Use the `with` context manager with database connections and cursors to ensure that they are closed once they are no longer needed. Where it was not feasible to use the `with` context manager without a huge refactor/rewrite, the cursors and connections are closed manually. --- scripts/maintenance/utilities.py | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'scripts/maintenance/utilities.py') diff --git a/scripts/maintenance/utilities.py b/scripts/maintenance/utilities.py index 886410c2..1fe14809 100644 --- a/scripts/maintenance/utilities.py +++ b/scripts/maintenance/utilities.py @@ -1,16 +1,6 @@ -import MySQLdb import re import configparser -def get_cursor(): - host = 'tux.uthsc.edu' - user = 'webqtlout' - passwd = 'webqtlout' - db = 'db_webqtl' - con = MySQLdb.Connect(db=db, host=host, user=user, passwd=passwd) - cursor = con.cursor() - return cursor, con - def clearspaces(s, default=None): if s: s = re.sub('\s+', ' ', s) -- cgit v1.2.3