Skip to content

Commit

Permalink
fixed issue with logging handlers not closing properly (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
panosatha authored May 29, 2024
1 parent df8ed07 commit 303b883
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flood_adapt/integrator/fiat_adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import gc
from pathlib import Path
from typing import List, Optional, Union

Expand Down Expand Up @@ -60,6 +61,9 @@ def __del__(self) -> None:
# Close fiat_logger
for handler in self.fiat_logger.handlers:
handler.close()
self.fiat_logger.handlers.clear()
# Use garbage collector to ensure file handlers are properly cleaned up
gc.collect()

def set_hazard(self, hazard: Hazard) -> None:
map_fn = hazard.flood_map_path
Expand Down
1 change: 1 addition & 0 deletions flood_adapt/integrator/sfincs_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __del__(self):
# Close the log file associated with the logger
for handler in self.sfincs_logger.handlers:
handler.close()
self.sfincs_logger.handlers.clear()
# Use garbage collector to ensure file handles are properly cleaned up
gc.collect()

Expand Down
1 change: 1 addition & 0 deletions flood_adapt/object_model/direct_impacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def preprocess_fiat(self):
fa.fiat_model.set_root(self.fiat_path)
fa.fiat_model.write()

# Delete instance of Adapter (together with all logging references)
del fa

def run_fiat(self):
Expand Down

0 comments on commit 303b883

Please sign in to comment.