diff --git a/src/score_db/experiments.py b/src/score_db/experiments.py index 4831100..0b8b064 100644 --- a/src/score_db/experiments.py +++ b/src/score_db/experiments.py @@ -369,7 +369,6 @@ def submit(self): def put_experiment(self): - engine = stm.get_engine_from_settings() session = stm.get_session() record = exp( @@ -440,6 +439,7 @@ def put_experiment(self): message = f'Attempt to {action} experiment record FAILED' error_msg = f'Failed to insert/update record - err: {err}' print(f'error_msg: {error_msg}') + session.close() else: message = f'Attempt to {action} experiment record SUCCEEDED' error_msg = None @@ -463,7 +463,6 @@ def put_experiment(self): def get_experiments(self): - engine = stm.get_engine_from_settings() session = stm.get_session() q = session.query( @@ -509,11 +508,13 @@ def get_experiments(self): except Exception as err: message = 'Request for experiment records FAILED' error_msg = f'Failed to get experiment records - err: {err}' + session.close() else: message = 'Request for experiment records SUCCEEDED' for idx, row in results.iterrows(): print(f'idx: {idx}, row: {row}') record_count = len(results.index) + session.close() details = {} # details['filters'] = self.filters diff --git a/src/score_db/expt_array_metrics.py b/src/score_db/expt_array_metrics.py index f0e3785..298ac39 100644 --- a/src/score_db/expt_array_metrics.py +++ b/src/score_db/expt_array_metrics.py @@ -672,6 +672,7 @@ def put_expt_array_metrics(self): session.close() else: + session.close() return self.failed_request('No expt array metric records were discovered to be inserted') return DbActionResponse( @@ -770,6 +771,7 @@ def get_expt_array_metrics(self): columns=ExptArrayMetricsData._fields ) except Exception as err: + session.close() trcbk = traceback.format_exc() msg = f'Problem casting array exeriment metrics query output into pandas ' \ f'DataFrame - err: {trcbk}' diff --git a/src/score_db/expt_file_counts.py b/src/score_db/expt_file_counts.py index dd92add..66cb3b8 100644 --- a/src/score_db/expt_file_counts.py +++ b/src/score_db/expt_file_counts.py @@ -634,6 +634,7 @@ def put_expt_file_counts(self): message = f'Attempt to insert experiment stored file counts record FAILED' error_msg = f'Failed to insert record - err: {err}' print(f'error_msg: {error_msg}') + session.close() else: message = f'Attempt to insert experiment stored file counts record SUCCEEDED' error_msg = None @@ -736,5 +737,6 @@ def get_expt_file_counts(self): ) print(f'response: {response}') - + + session.close() return response diff --git a/src/score_db/expt_metrics.py b/src/score_db/expt_metrics.py index 6c8acc6..73e8f64 100644 --- a/src/score_db/expt_metrics.py +++ b/src/score_db/expt_metrics.py @@ -597,7 +597,6 @@ def put_expt_metrics_data(self): def get_experiment_metrics(self): - engine = stm.get_engine_from_settings() session = stm.get_session() # set basic query diff --git a/src/score_db/metric_types.py b/src/score_db/metric_types.py index 2ccaca1..e7cf2c2 100644 --- a/src/score_db/metric_types.py +++ b/src/score_db/metric_types.py @@ -219,7 +219,6 @@ def submit(self): def put_metric_type(self): - engine = stm.get_engine_from_settings() session = stm.get_session() insert_stmt = insert(mt).values( @@ -290,7 +289,6 @@ def put_metric_type(self): def get_metric_types(self): - engine = stm.get_engine_from_settings() session = stm.get_session() q = session.query( diff --git a/src/score_db/score_table_models.py b/src/score_db/score_table_models.py index 6be9781..dd8a358 100644 --- a/src/score_db/score_table_models.py +++ b/src/score_db/score_table_models.py @@ -48,7 +48,7 @@ def get_engine(user, passwd, host, port, db): db_engine = create_engine( url, - pool_size=50, + pool_size=15, echo=False, connect_args={"options": "-c timezone=utc"} ) @@ -332,7 +332,4 @@ class InstrumentMeta(Base): Base.metadata.create_all(engine) def get_session(): - engine = get_engine_from_settings() - Session = sessionmaker(bind=engine) - return Session()