Skip to content

Commit

Permalink
Close connections to db, and print any exceptions encountered
Browse files Browse the repository at this point in the history
Were were running out of db connections, but not seeing the exception
message, because it's only raised in the original process if we ask for
the result.
  • Loading branch information
Bjwebb committed Aug 28, 2024
1 parent 5dc9781 commit 5799d88
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion iatidata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import subprocess
import tempfile
import time
import traceback
import zipfile
from collections import defaultdict
from datetime import datetime
Expand Down Expand Up @@ -305,7 +306,9 @@ def load_dataset(dataset: iatikit.Dataset) -> None:
path = pathlib.Path(dataset.data_path)
prefix, filename = path.parts[-2:]

with get_engine().begin() as connection:
engine = get_engine()

with engine.begin() as connection:
connection.execute(
insert(
table(
Expand Down Expand Up @@ -334,6 +337,8 @@ def load_dataset(dataset: iatikit.Dataset) -> None:
)
)

engine.dispose()


def create_database_schema():
if schema:
Expand Down Expand Up @@ -363,6 +368,12 @@ def load(processes: int, sample: Optional[int] = None) -> None:
executor.submit(load_dataset, dataset) for dataset in datasets_sample
]
concurrent.futures.wait(futures)
# We have to get the result (even though we don't use it) in order to get the exceptions
for future in futures:
try:
future.result()
except Exception:
print(traceback.format_exc())

engine = get_engine()
with engine.begin() as connection:
Expand Down

0 comments on commit 5799d88

Please sign in to comment.