From 6baef49f9d9d196b89b37dbd30ee83135e1e09ac Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 23 Feb 2020 00:08:34 +0100 Subject: [PATCH] add after_shutdown hook --- python/src/deltachat/account.py | 1 + python/src/deltachat/hookspec.py | 4 ++++ python/src/deltachat/tracker.py | 2 ++ python/tests/test_lowlevel.py | 12 ++++++++++++ 4 files changed, 19 insertions(+) diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index dcff14191..2a02b22a8 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -522,6 +522,7 @@ class Account(object): deltachat.clear_context_callback(self._dc_context) del self._dc_context atexit.unregister(self.shutdown) + self._pm.hook.after_shutdown() def set_location(self, latitude=0.0, longitude=0.0, accuracy=0.0): """set a new location. It effects all chats where we currently diff --git a/python/src/deltachat/hookspec.py b/python/src/deltachat/hookspec.py index 10ae6cb7a..092256c11 100644 --- a/python/src/deltachat/hookspec.py +++ b/python/src/deltachat/hookspec.py @@ -31,6 +31,10 @@ class PerAccount: def log_line(self, message): """ log a message related to the account. """ + @account_hookspec + def after_shutdown(self): + """ Called when the account has been shutdown. """ + @account_hookspec def configure_completed(self, success): """ Called when a configure process completed. """ diff --git a/python/src/deltachat/tracker.py b/python/src/deltachat/tracker.py index 872d72f39..6e92186a5 100644 --- a/python/src/deltachat/tracker.py +++ b/python/src/deltachat/tracker.py @@ -38,6 +38,8 @@ class ConfigureFailed(RuntimeError): class ConfigureTracker: + ConfigureFailed = ConfigureFailed + def __init__(self): self._configure_events = Queue() self._smtp_finished = Event() diff --git a/python/tests/test_lowlevel.py b/python/tests/test_lowlevel.py index 733cbe825..74833f205 100644 --- a/python/tests/test_lowlevel.py +++ b/python/tests/test_lowlevel.py @@ -1,5 +1,6 @@ from __future__ import print_function from deltachat import capi, cutil, const, set_context_callback, clear_context_callback +from deltachat.hookspec import account_hookimpl from deltachat.capi import ffi from deltachat.capi import lib @@ -18,7 +19,18 @@ def test_callback_None2int(): def test_dc_close_events(tmpdir, acfactory): ac1 = acfactory.get_unconfigured_account() + + # register after_shutdown function + l = [] + class ShutdownPlugin: + @account_hookimpl + def after_shutdown(self): + assert not hasattr(ac1, "_dc_context") + l.append(1) + ac1.add_account_plugin(ShutdownPlugin()) + assert hasattr(ac1, "_dc_context") ac1.shutdown() + assert l == [1] def find(info_string): evlog = ac1._evtracker