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

Added exception handler in convert function to allow cleanup of expor… #46

Merged
Show file tree
Hide file tree
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
23 changes: 18 additions & 5 deletions focus_converter_base/focus_converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class FocusConverter:
plans: Dict[str, List[ConversionPlan]]
data_loader: DataLoader
data_exporter: DataExporter
data_exporter: DataExporter = None

# set of plan variables for horizontal transformation plans
h_collected_columns: List[str] # collected columns
Expand Down Expand Up @@ -183,8 +183,21 @@ def apply_plan(self, lf: pl.LazyFrame) -> pl.LazyFrame:
return lf

def convert(self):
error = None

for lf in self.data_loader.data_scanner():
lf = self.apply_plan(lf=lf)
self.data_exporter.collect(
lf=lf, collected_columns=list(set(self.h_collected_columns))
)
try:
lf = self.apply_plan(lf=lf)
self.data_exporter.collect(
lf=lf, collected_columns=list(set(self.h_collected_columns))
)
except Exception as e:
error = e
break

if error is not None:
# cleanup data export now that we have to close all subprocesses
if self.data_exporter:
self.data_exporter.close()

raise error
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ def __init__(
[p.start() for p in processes]

def __del__(self):
if self.__queue__:
self.close()

def close(self):
for _ in range(len(self.__processes__)):
self.__queue__.put(None)

for p in self.__processes__:
p.join()
p.close()
del self.__queue__
self.__queue__ = None

def collect(self, lf: pl.LazyFrame, collected_columns: List[str]):
if not self.__export_include_source_columns__:
Expand Down