[meld] filediff, matchers.helpers: Improve matcher process clean up (#565)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] filediff, matchers.helpers: Improve matcher process clean up (#565)
- Date: Fri, 19 Mar 2021 23:48:42 +0000 (UTC)
commit 8ed5befe2a7c9d5bbacb109112b3c01978c54005
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Mar 20 09:37:50 2021 +1000
filediff, matchers.helpers: Improve matcher process clean up (#565)
We try to handle shut down and clean up of our multiprocessing matcher
process when we remove FileDiff tabs, but this wasn't working properly.
We know, for a start, that we have some garbage collection issues around
FileDiff in general.
Since __del__ is not guaranteed to get called (and in fact was not
getting called at all for this specific case in some minimal testing),
this commit moves the logic to a specific stop() call, which is invoked
in our FileDiff close handling.
This commit also cleans up our handling slightly to avoid spurious
errors when we close a file comparison tab before the matcher process
has been started (since it starts on idle).
meld/filediff.py | 10 +++++-----
meld/matchers/helpers.py | 11 +++++++----
2 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index e40f1293..d06c538f 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1246,12 +1246,12 @@ class FileDiff(Gtk.VBox, MeldDoc):
for buf in self.textbuffer:
buf.data.disconnect_monitor()
- # TODO: This should not be necessary; remove if and when we
- # figure out what's keeping MeldDocs alive for too long.
try:
- del self._cached_match
- except AttributeError:
- pass
+ self._cached_match.stop()
+ except Exception:
+ # Ignore any cross-process exceptions that happen when
+ # shutting down our matcher process.
+ log.exception('Failed to shut down matcher process')
# TODO: Base the return code on something meaningful for VC tools
self.close_signal.emit(0)
return response
diff --git a/meld/matchers/helpers.py b/meld/matchers/helpers.py
index 3a3d1372..7e0f7e88 100644
--- a/meld/matchers/helpers.py
+++ b/meld/matchers/helpers.py
@@ -68,11 +68,14 @@ class CachedSequenceMatcher:
self.queued_matches = {}
GLib.idle_add(self.thread.start)
- def __del__(self):
+ def stop(self) -> None:
self.tasks.put((MatcherWorker.END_TASK, ('', '')))
- self.thread.join(self.TASK_GRACE_PERIOD)
- if self.thread.exitcode is None:
- self.thread.terminate()
+ if self.thread.is_alive():
+ self.thread.join(self.TASK_GRACE_PERIOD)
+ if self.thread.exitcode is None:
+ self.thread.terminate()
+ self.cache = {}
+ self.queued_matches = {}
def match(self, text1, textn, cb):
texts = (text1, textn)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]