aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-03-08 08:00:16 +0300
committerFrederick Muriuki Muriithi2022-03-08 08:00:16 +0300
commiteae345ed252c01e541d64c7e5b60b488d84268c6 (patch)
tree819fe27db22b757da2eeafd438abe01ca8ab8cc8 /scripts
parent84f51f48a59da93e287d793d983ace4d06ccb483 (diff)
downloadgenenetwork3-eae345ed252c01e541d64c7e5b60b488d84268c6.tar.gz
Create database connections within context managers
Use the `with` context manager to open database connections, so as to ensure that those connections are closed once the call is completed. This hopefully avoids the 'too many connections' error
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/partial_correlations.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/scripts/partial_correlations.py b/scripts/partial_correlations.py
index ee442df..f203daa 100755
--- a/scripts/partial_correlations.py
+++ b/scripts/partial_correlations.py
@@ -35,19 +35,19 @@ def cleanup_string(the_str):
return the_str.strip('"\t\n\r ')
def run_partial_corrs(args):
- try:
- conn, _cursor_object = database_connector()
- return partial_correlations_entry(
- conn, cleanup_string(args.primary_trait),
- tuple(cleanup_string(args.control_traits).split(",")),
- cleanup_string(args.method), args.criteria,
- cleanup_string(args.target_database))
- except Exception as exc:
- print(traceback.format_exc(), file=sys.stderr)
- return {
- "status": "exception",
- "message": traceback.format_exc()
- }
+ with database_connector() as conn:
+ try:
+ return partial_correlations_entry(
+ conn, cleanup_string(args.primary_trait),
+ tuple(cleanup_string(args.control_traits).split(",")),
+ cleanup_string(args.method), args.criteria,
+ cleanup_string(args.target_database))
+ except Exception as exc:
+ print(traceback.format_exc(), file=sys.stderr)
+ return {
+ "status": "exception",
+ "message": traceback.format_exc()
+ }
def enter():
args = process_cli_arguments()