From e4324b03b418d122402f0886742f25cf695ff6df Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Fri, 10 Dec 2021 15:58:51 +0100 Subject: [PATCH] reset filter only after cancelling the search Fixes issue where the UI froze when removing the last char of a query while still a search was running. This caused the search thread to append to the newly truncated file, resulting in megabytes of null bytes at the beginning. --- filterwidget.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/filterwidget.py b/filterwidget.py index e972657..8478665 100644 --- a/filterwidget.py +++ b/filterwidget.py @@ -43,11 +43,6 @@ class FilterTask(QRunnable): # print("starting thread ", threading.currentThread()) self.on_before() - # delay the filtering. This work arounds a race condition. For some reasons, even though we have locks - # to ensure that only one thread writes to the target file, it happened that the file was not correctly - # truncated and started with null bytes. Sometimes several MB of null bytes. My guess is that this is - # caused by async write operations. - time.sleep(0.5) if self.aborted: self.on_finish() @@ -83,7 +78,7 @@ class FilterTask(QRunnable): break finally: self.on_finish() - #print("dome thread ", threading.currentThread()) + # print("dome thread ", threading.currentThread()) class FilterWidget(QWidget): @@ -160,13 +155,14 @@ class FilterWidget(QWidget): query = self.query_field.text() ignore_case = self.ignore_case.isChecked() is_regex = self.is_regex.isChecked() - if len(query) == 0: - self.reset_filter() - return # cancel previous search self._cancel_search() + if len(query) == 0: + self.reset_filter() + return + try: flags = re.IGNORECASE if ignore_case else 0 if is_regex: