Skip to content

Commit 2eb66df

Browse files
Try to fix crash "QThread: Destroyed while thread is still running", call QThread.wait before reset QThread object to None
1 parent 40f855e commit 2eb66df

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core/buffer.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,12 @@ def start_marker_input_monitor_thread(self, callback_tag):
294294

295295
def stop_marker_input_monitor_thread(self):
296296
if self.fetch_marker_input_thread is not None and self.fetch_marker_input_thread.isRunning():
297-
self.fetch_marker_input_thread.running_flag = False
297+
self.fetch_marker_input_thread.stop()
298+
# NOTE:
299+
# We need call QThread.wait() function before reset QThread object to None.
300+
# Set to None will trigger Python GC release QThread object, if QThread is still running,
301+
# Segment falut "QThread: Destroyed while thread is still running" will throw, it will crash EAF.
302+
self.fetch_marker_input_thread.wait()
298303
self.fetch_marker_input_thread = None
299304

300305
def start_search_input_monitor_thread(self, callback_tag):
@@ -306,6 +311,11 @@ def start_search_input_monitor_thread(self, callback_tag):
306311
def stop_search_input_monitor_thread(self):
307312
if self.fetch_search_input_thread is not None and self.fetch_search_input_thread.isRunning():
308313
self.fetch_search_input_thread.stop()
314+
# NOTE:
315+
# We need call QThread.wait() function before reset QThread object to None.
316+
# Set to None will trigger Python GC release QThread object, if QThread is still running,
317+
# Segment falut "QThread: Destroyed while thread is still running" will throw, it will crash EAF.
318+
self.fetch_search_input_thread.wait()
309319
self.fetch_search_input_thread = None
310320

311321
@abstract
@@ -491,6 +501,9 @@ def run(self):
491501

492502
time.sleep(0.1)
493503

504+
def stop(self):
505+
self.running_flag = False
506+
494507
class FetchSearchInputThread(QThread):
495508

496509
search_changed = pyqtSignal(str, str)

0 commit comments

Comments
 (0)