diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 51b73f37e..55f8c6d5c 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -15,7 +15,7 @@ from .message import Message from .contact import Contact from .tracker import ImexTracker, ConfigureTracker from . import hookspec -from .events import FFIEventLogger, EventThread +from .events import EventThread class MissingCredentials(ValueError): @@ -41,8 +41,6 @@ class Account(object): self._logging = logging self.add_account_plugin(self) - if logging: - self.add_account_plugin(FFIEventLogger(self, logid=str(id(self))[:5])) self._dc_context = ffi.gc( lib.dc_context_new(ffi.NULL, as_dc_charpointer(os_name)), @@ -75,7 +73,7 @@ class Account(object): # def __del__(self): # self.shutdown() - def ac_log_line(self, msg): + def log(self, msg): if self._logging: self._pm.hook.ac_log_line(message=msg) @@ -587,14 +585,14 @@ class Account(object): def stop_scheduler(self): """ stop core scheduler if it is running. """ - self.ac_log_line("stop_ongoing") + self.log("stop_ongoing") self.stop_ongoing() if self.is_started(): - self.ac_log_line("context_shutdown (stop core scheduler)") + self.log("context_shutdown (stop core scheduler)") lib.dc_context_shutdown(self._dc_context) else: - self.ac_log_line("stop_scheduler called on non-running context") + self.log("stop_scheduler called on non-running context") def shutdown(self, wait=True): """ shutdown and destroy account (stop callback thread, close and remove @@ -604,14 +602,14 @@ class Account(object): return if self._event_thread.is_alive(): - self.ac_log_line("stop threads") + self.log("stop threads") self._event_thread.stop(wait=False) self.stop_scheduler() - self.ac_log_line("dc_close") + self.log("dc_close") lib.dc_close(dc_context) - self.ac_log_line("wait threads for real") + self.log("wait threads for real") if wait: self._event_thread.stop(wait=wait) self._dc_context = None diff --git a/python/src/deltachat/events.py b/python/src/deltachat/events.py index 5c3dbf9ff..9fc50ef56 100644 --- a/python/src/deltachat/events.py +++ b/python/src/deltachat/events.py @@ -38,13 +38,7 @@ class FFIEventLogger: @account_hookimpl def ac_process_ffi_event(self, ffi_event): - self._log_event(ffi_event) - - def _log_event(self, ffi_event): - # don't show events that are anyway empty impls now - if ffi_event.name == "DC_EVENT_GET_STRING": - return - self.account.ac_log_line(str(ffi_event)) + self.account.log(str(ffi_event)) @account_hookimpl def ac_log_line(self, message): @@ -97,7 +91,7 @@ class FFIEventTracker: assert not rex.match(ev.name), "event found {}".format(ev) def get_matching(self, event_name_regex, check_error=True, timeout=None): - self.account.ac_log_line("-- waiting for event with regex: {} --".format(event_name_regex)) + self.account.log("-- waiting for event with regex: {} --".format(event_name_regex)) rex = re.compile("(?:{}).*".format(event_name_regex)) while 1: ev = self.get(timeout=timeout, check_error=check_error) @@ -138,9 +132,9 @@ class EventThread(threading.Thread): @contextmanager def log_execution(self, message): - self.account.ac_log_line(message + " START") + self.account.log(message + " START") yield - self.account.ac_log_line(message + " FINISHED") + self.account.log(message + " FINISHED") def stop(self, wait=False): self._thread_quitflag = True @@ -181,7 +175,7 @@ class EventThread(threading.Thread): ffi_event = FFIEvent(name=evt_name, data1=data1, data2=data2) self.account._pm.hook.ac_process_ffi_event(account=self, ffi_event=ffi_event) for name, kwargs in self._map_ffi_event(ffi_event): - self.account.ac_log_line("calling hook name={} kwargs={}".format(name, kwargs)) + # self.account.log("calling hook name={} kwargs={}".format(name, kwargs)) hook = getattr(self.account._pm.hook, name) try: hook(**kwargs) diff --git a/python/src/deltachat/hookspec.py b/python/src/deltachat/hookspec.py index 00ec36d98..b0e896aaf 100644 --- a/python/src/deltachat/hookspec.py +++ b/python/src/deltachat/hookspec.py @@ -15,8 +15,9 @@ global_hookimpl = pluggy.HookimplMarker(global_spec_name) class PerAccount: """ per-Account-instance hook specifications. - Except for ac_process_ffi_event all hooks are executed - in the thread which calls Account.wait_shutdown(). + All hooks are executed in a dedicated Event thread. + Hooks are not allowed to block/last long as this + blocks overall event processing on the python side. """ @classmethod def _make_plugin_manager(cls):