Skip to content

Commit

Permalink
add not close writer warnning
Browse files Browse the repository at this point in the history
  • Loading branch information
tiankongdeguiji committed Oct 9, 2024
1 parent 35843a5 commit 5659f58
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions tzrec/datasets/csv_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,4 @@ def close(self) -> None:
"""Close and commit data."""
if self._writer is not None:
self._writer.close()
super().close()
7 changes: 6 additions & 1 deletion tzrec/datasets/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from tzrec.features.feature import BaseFeature
from tzrec.protos import data_pb2
from tzrec.utils.load_class import get_register_class_meta
from tzrec.utils.logging_util import logger

_DATASET_CLASS_MAP = {}
_READER_CLASS_MAP = {}
Expand Down Expand Up @@ -429,7 +430,11 @@ def write(self, output_dict: OrderedDict[str, pa.Array]) -> None:

def close(self) -> None:
"""Close and commit data."""
pass
self._lazy_inited = False

def __del__(self) -> None:
if self._lazy_inited:
logger.warning(f"You should close {self.__class__.__name__} explicitly.")


def create_reader(
Expand Down
1 change: 1 addition & 0 deletions tzrec/datasets/odps_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,4 @@ def close(self) -> None:
raise RuntimeError(
f"Fail to commit write session: {self._sess_req.session_id}"
)
super().close()
1 change: 1 addition & 0 deletions tzrec/datasets/parquet_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ def close(self) -> None:
"""Close and commit data."""
if self._writer is not None:
self._writer.close()
super().close()
3 changes: 3 additions & 0 deletions tzrec/tools/tdm/gen_tree/tree_search_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def save(self) -> None:
node_table_dict["weight"] = pa.array(weight)
node_table_dict["features"] = pa.array(features)
node_writer.write(node_table_dict)
node_writer.close()

edge_writer = create_writer(
self.output_file + "edge_table", **self.dataset_kwargs
Expand All @@ -155,6 +156,7 @@ def save(self) -> None:
edge_table_dict["dst_id"] = pa.array(dst_ids)
edge_table_dict["weight"] = pa.array(weight)
edge_writer.write(edge_table_dict)
edge_writer.close()

else:
if not os.path.exists(self.output_file):
Expand Down Expand Up @@ -198,6 +200,7 @@ def save_predict_edge(self) -> None:
edge_table_dict["dst_id"] = pa.array(dst_ids)
edge_table_dict["weight"] = pa.array(weight)
writer.write(edge_table_dict)
writer.close()
else:
with open(
os.path.join(self.output_file, "predict_edge_table.txt"), "w"
Expand Down

0 comments on commit 5659f58

Please sign in to comment.