Skip to content

Commit

Permalink
Merge pull request #179 from BrainLesion/173
Browse files Browse the repository at this point in the history
added tempfile
  • Loading branch information
Hendrik-code authored Jan 31, 2025
2 parents f44db2b + b3182c3 commit 8294541
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions panoptica/panoptica_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import atexit
import warnings
import tempfile

# Set start method based on the operating system
try:
Expand Down Expand Up @@ -83,12 +84,15 @@ def __init__(
else:
out_file_path += ".tsv" # add extension

out_buffer_file: Path = Path(out_file_path).parent.joinpath(
"panoptica_aggregator_tmp.tsv"
)
self.__output_buffer_file = out_buffer_file
# buffer_file = tempfile.NamedTemporaryFile()
# out_buffer_file: Path = Path(out_file_path).parent.joinpath("panoptica_aggregator_tmp.tsv")
# self.tmpfile =
self.__output_buffer_file = tempfile.NamedTemporaryFile(
delete=False
).name # out_buffer_file
# print(self.__output_buffer_file)

Path(out_file_path).parent.mkdir(parents=True, exist_ok=True)
Path(out_file_path).parent.mkdir(parents=False, exist_ok=True)
self.__output_file = out_file_path

header = ["subject_name"] + [
Expand All @@ -113,10 +117,6 @@ def __init__(
"+".join(header_list)
), "Hash of header not the same! You are using a different setup!"

if out_buffer_file.exists():
os.remove(out_buffer_file)
open(out_buffer_file, "a").close()

if continue_file:
with inevalfilelock:
with filelock:
Expand All @@ -127,7 +127,7 @@ def __init__(

def __exist_handler(self):
"""Handles cleanup upon program exit by removing the temporary output buffer file."""
if self.__output_buffer_file is not None and self.__output_buffer_file.exists():
if Path(self.__output_buffer_file).exists():
os.remove(str(self.__output_buffer_file))

def make_statistic(self) -> Panoptica_Statistic:
Expand Down

0 comments on commit 8294541

Please sign in to comment.