1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-04 10:19:16 +02:00

actually we can wait for threads to stop now, don't know why it didn't work before.

we can also attempt to free dc_context now.
This commit is contained in:
holger krekel 2018-09-13 12:50:51 +02:00
parent 75f8169072
commit a124a6dd86
2 changed files with 8 additions and 21 deletions

View file

@ -112,7 +112,7 @@ class Chat(object):
@cached_property @cached_property
def dc_chat_t(self): def dc_chat_t(self):
return capi.lib.get_chat(self.id) return capi.lib.dc_get_chat(self.dc_context, self.id)
def __del__(self): def __del__(self):
capi.lib.dc_chat_unref(self.dc_chat_t) capi.lib.dc_chat_unref(self.dc_chat_t)
@ -131,7 +131,7 @@ class Message(object):
id = attrib_int() id = attrib_int()
@cached_property @cached_property
def dc_msg(self): def dc_msg_t(self):
return capi.lib.dc_get_msg(self.dc_context, self.id) return capi.lib.dc_get_msg(self.dc_context, self.id)
def __del__(self): def __del__(self):
@ -139,11 +139,11 @@ class Message(object):
@property @property
def text(self): def text(self):
return ffi_unicode(capi.lib.dc_msg_get_text(self.dc_msg)) return ffi_unicode(capi.lib.dc_msg_get_text(self.dc_msg_t))
@property @property
def chat(self): def chat(self):
chat_id = capi.lib.dc_msg_get_chat_id(self.dc_msg) chat_id = capi.lib.dc_msg_get_chat_id(self.dc_msg_t)
return Chat(self.dc_context, chat_id) return Chat(self.dc_context, chat_id)
@ -159,14 +159,8 @@ class Account(object):
self._evlogger = EventLogger(self.dc_context, logid) self._evlogger = EventLogger(self.dc_context, logid)
self._threads = IOThreads(self.dc_context) self._threads = IOThreads(self.dc_context)
def __del__(self): def __del__(self, dc_context_unref=capi.lib.dc_context_unref):
# XXX this causes currently a segfault because dc_context_unref(self.dc_context)
# the threads still have a reference to dc_context
#
# capi.lib.dc_context_unref(self.dc_context)
#
# let's for now leak memory instead of causing segfaults
pass
def set_config(self, **kwargs): def set_config(self, **kwargs):
for name, value in kwargs.items(): for name, value in kwargs.items():
@ -211,13 +205,7 @@ class Account(object):
def shutdown(self): def shutdown(self):
deltachat.clear_context_callback(self.dc_context) deltachat.clear_context_callback(self.dc_context)
self._threads.stop(wait=False) self._threads.stop(wait=True)
# XXX actually we'd like to wait but the smtp/imap
# interrupt idle calls do not seem to release the
# blocking call to smtp|imap idle. This means we
# also can't now close the database because the
# threads might still need it.
# capi.lib.dc_close(self.dc_context)
def _process_event(self, ctx, evt_name, data1, data2): def _process_event(self, ctx, evt_name, data1, data2):
assert ctx == self.dc_context assert ctx == self.dc_context
@ -248,8 +236,6 @@ class IOThreads:
def stop(self, wait=False): def stop(self, wait=False):
self._thread_quitflag = True self._thread_quitflag = True
# XXX interrupting does not quite work yet, the threads keep idling
print("interrupting smtp and idle")
capi.lib.dc_interrupt_imap_idle(self.dc_context) capi.lib.dc_interrupt_imap_idle(self.dc_context)
capi.lib.dc_interrupt_smtp_idle(self.dc_context) capi.lib.dc_interrupt_smtp_idle(self.dc_context)
if wait: if wait:

View file

@ -28,6 +28,7 @@ class TestOfflineAccount:
assert chat2.id == chat.id assert chat2.id == chat.id
assert chat == chat2 assert chat == chat2
assert not (chat != chat2) assert not (chat != chat2)
assert chat.dc_chat_t
def test_message(self, acfactory): def test_message(self, acfactory):
ac1 = acfactory.get_offline_account() ac1 = acfactory.get_offline_account()