Skip to content

Commit

Permalink
Merge pull request #58 from bmwcarit/IDCEVODEV-13223
Browse files Browse the repository at this point in the history
Fix endless file reading even with a set stop event
  • Loading branch information
yen3 authored Jul 4, 2023
2 parents 07cc823 + 8bd57a9 commit 529fdb1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions dlt/dlt.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def __getitem__(self, index):
def _open_file(self):
"""Open the configured file for processing"""
file_opened = False
while not self.stop_reading.is_set() and not self.stop_reading_proc.is_set():
while not self._is_stop_reading_set():
if dltlib.dlt_file_open(ctypes.byref(self), self.filename, self.verbose) >= DLT_RETURN_OK:
file_opened = True
break
Expand All @@ -791,6 +791,9 @@ def _log_message_progress(self):
self.msg.ctid,
)

def _is_stop_reading_set(self):
return self.stop_reading.is_set() or self.stop_reading_proc.is_set()

def __iter__(self): # pylint: disable=too-many-branches
"""Iterate over messages in the file"""
logger.debug("Starting File Read")
Expand All @@ -804,17 +807,17 @@ def __iter__(self): # pylint: disable=too-many-branches
self._open_file()

found_data = False
while (
not self.stop_reading.is_set() and not self.stop_reading_proc.is_set()
) or corruption_check_try: # pylint: disable=too-many-nested-blocks
while not self._is_stop_reading_set() or corruption_check_try: # pylint: disable=too-many-nested-blocks
os_stat = os.stat(self.filename)
mtime = os_stat.st_mtime

if mtime != cached_mtime and os_stat.st_size or corruption_check_try:
cached_mtime = mtime
corruption_check_try = False

while dltlib.dlt_file_read(ctypes.byref(self), self.verbose) >= DLT_RETURN_OK:
while not self._is_stop_reading_set() and (
dltlib.dlt_file_read(ctypes.byref(self), self.verbose) >= DLT_RETURN_OK
):
found_data = True
if (
self.filter
Expand Down

0 comments on commit 529fdb1

Please sign in to comment.