fix #1720 -- don't wait for the daemon eventhread to terminate but count on it to eventually die

This commit is contained in:
holger krekel
2020-07-15 16:53:30 +02:00
parent f461e2a2fd
commit a27b379ce0
3 changed files with 17 additions and 3 deletions

View File

@@ -609,10 +609,14 @@ class Account(object):
self.log("remove dc_context references")
# the dc_context_unref triggers get_next_event to return ffi.NULL
# which in turns makes the event thread finish execution
self._event_thread.mark_shutdown()
self._dc_context = None
self.log("wait for event thread to finish")
self._event_thread.wait()
# the following wait is left out for now because it can fail if
# a) python code holds an extra self._dc_context reference
# b) the core does not manage to send a NULL through get_next_event()
# self.log("wait for event thread to finish")
# self._event_thread.wait()
self._shutdown_event.set()

View File

@@ -162,6 +162,10 @@ class DirectImap:
requested = [b'BODY.PEEK[HEADER]', FLAGS]
for uid, data in self.conn.fetch(messages, requested).items():
body_bytes = data[b'BODY[HEADER]']
if not body_bytes:
log("Message", uid, "has empty body")
continue
flags = data[FLAGS]
path = pathlib.Path(str(dir)).joinpath("IMAP", self.logid, imapfolder)
path.mkdir(parents=True, exist_ok=True)

View File

@@ -139,6 +139,7 @@ class EventThread(threading.Thread):
self.account = account
super(EventThread, self).__init__(name="events")
self.setDaemon(True)
self._marked_for_shutdown = False
self.start()
@contextmanager
@@ -147,6 +148,9 @@ class EventThread(threading.Thread):
yield
self.account.log(message + " FINISHED")
def mark_shutdown(self):
self._marked_for_shutdown = True
def wait(self):
if self == threading.current_thread():
# we are in the callback thread and thus cannot
@@ -164,10 +168,12 @@ class EventThread(threading.Thread):
lib.dc_get_event_emitter(self.account._dc_context),
lib.dc_event_emitter_unref,
)
while 1:
while not self._marked_for_shutdown:
event = lib.dc_get_next_event(event_emitter)
if event == ffi.NULL:
break
if self._marked_for_shutdown:
break
evt = lib.dc_event_get_id(event)
data1 = lib.dc_event_get_data1_int(event)
# the following code relates to the deltachat/_build.py's helper