From 138d5b7a02dac1d0fed2dcbdf6e5684195b2dc48 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 4 May 2022 00:57:27 +0200 Subject: [PATCH] fix segfaults with python runs -- i don't get them anymore, and can also control-c at will --- python/src/deltachat/account.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index f4366aaea..3a895c292 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -695,28 +695,24 @@ class Account(object): if self._dc_context is None: return - self.stop_io() - - self.log("remove dc_context references") - - # if _dc_context is unref'ed the event thread should quickly - # receive the termination signal. However, some python code might - # still hold a reference and so we use a secondary signal - # to make sure the even thread terminates if it receives any new - # event, indepedently from waiting for the core to send NULL to - # get_next_event(). + # mark the event thread for shutdown (latest on next incoming event) self._event_thread.mark_shutdown() - self._dc_context = None + + # stop_io also causes an info event that will terminate the event thread + self.stop_io() self.log("wait for event thread to finish") try: - self._event_thread.wait(timeout=2) + self._event_thread.wait(timeout=5) except RuntimeError as e: self.log("Waiting for event thread failed: {}".format(e)) if self._event_thread.is_alive(): self.log("WARN: event thread did not terminate yet, ignoring.") + self.log("remove dc_context references, making the Account unusuable") + self._dc_context = None + self._shutdown_event.set() hook = hookspec.Global._get_plugin_manager().hook