Skip to content

Commit

Permalink
Fix endless file reading even with a set stop event
Browse files Browse the repository at this point in the history
Problem: when a dlt file always has incoming dlt messages, the file
reading fails to stop even when users set the stop_reading_event.
Because we dont check the status of stop_reading_event while reading dlt
file returns OK, so the set stop_reading_event wont be perceived

Solution: while reading dlt file returns OK, we have another check of
the status of stop_reading_event, so that the reading could be stopped
accordingly
  • Loading branch information
hongjin.zhou committed Jun 30, 2023
1 parent 07cc823 commit 8bd57a9
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 8bd57a9

Please sign in to comment.