Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close connections to db, and print any exceptions encountered #54

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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