diff --git a/filterwidget.py b/filterwidget.py index 2ea16f0..e972657 100644 --- a/filterwidget.py +++ b/filterwidget.py @@ -43,6 +43,14 @@ 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() + for listener in self.filter_match_found_listeners: listener(-1, -1) # notify listeners that a new search started @@ -138,6 +146,9 @@ class FilterWidget(QWidget): if self.filter_task: # print("cancel started ", time.time()) self.filter_task.aborted = True + # wait until the previous search is aborted + with self._lock: + pass def reset_filter(self): self.filter_model.truncate()