Commit 1e905c5f by Oleksandr Barabash

no file update

parent 3b16ace6
...@@ -7,7 +7,7 @@ import signal ...@@ -7,7 +7,7 @@ import signal
import sys import sys
from asyncio import AbstractEventLoop from asyncio import AbstractEventLoop
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from typing import Any from typing import Any, Optional
from absl import app, flags from absl import app, flags
from marshmallow import EXCLUDE from marshmallow import EXCLUDE
...@@ -44,7 +44,11 @@ class CSVLogger(PacketLogger): ...@@ -44,7 +44,11 @@ class CSVLogger(PacketLogger):
BREAK_LINE = "\r\n" BREAK_LINE = "\r\n"
def __init__(self, file_path: str): def __init__(self, file_path: Optional[str] = None):
self.file_path = file_path
self.file = None
if file_path is not None:
self.file_path = file_path self.file_path = file_path
is_file_exists = os.path.exists(self.file_path) is_file_exists = os.path.exists(self.file_path)
self.file = open(self.file_path, "a+") self.file = open(self.file_path, "a+")
...@@ -65,6 +69,9 @@ class CSVLogger(PacketLogger): ...@@ -65,6 +69,9 @@ class CSVLogger(PacketLogger):
# noinspection PyBroadException # noinspection PyBroadException
def write(self, data: str) -> None: def write(self, data: str) -> None:
""" Try write """ """ Try write """
if self.file is None:
return
while True: while True:
try: try:
self.file.write(data) self.file.write(data)
...@@ -88,6 +95,7 @@ class CSVLogger(PacketLogger): ...@@ -88,6 +95,7 @@ class CSVLogger(PacketLogger):
def save(self) -> None: def save(self) -> None:
""" Save data """ """ Save data """
if self.file is not None:
self.file.flush() self.file.flush()
self.file.close() self.file.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment