refactor some python infra, and don't do shutdown on __del__, it's not prepared for running during teardown

This commit is contained in:
holger krekel
2020-05-24 15:36:20 +02:00
parent 7f4627356b
commit fa3ee4205d
3 changed files with 21 additions and 23 deletions

View File

@@ -67,8 +67,8 @@ class Account(object):
""" re-enable logging. """
self._logging = True
def __del__(self):
self.shutdown()
# def __del__(self):
# self.shutdown()
def log(self, msg):
if self._logging:

View File

@@ -77,9 +77,26 @@ class FFIEventTracker:
timeout = timeout if timeout is not None else self._timeout
ev = self._event_queue.get(timeout=timeout)
if check_error and ev.name == "DC_EVENT_ERROR":
raise ValueError(str(ev))
raise ValueError("unexpected event: {}".format(ev))
return ev
def iter_events(self, timeout=None, check_error=True):
while 1:
yield self.get(timeout=timeout, check_error=check_error)
def get_matching(self, event_name_regex, check_error=True, timeout=None):
rex = re.compile("(?:{}).*".format(event_name_regex))
for ev in self.iter_events(timeout=timeout, check_error=check_error):
if rex.match(ev.name):
return ev
def get_info_matching(self, regex):
rex = re.compile("(?:{}).*".format(regex))
while 1:
ev = self.get_matching("DC_EVENT_INFO")
if rex.match(ev.data2):
return ev
def ensure_event_not_queued(self, event_name_regex):
__tracebackhide__ = True
rex = re.compile("(?:{}).*".format(event_name_regex))
@@ -98,25 +115,6 @@ class FFIEventTracker:
print("** SECUREJOINT-INVITER PROGRESS {}".format(target), self.account)
break
def get_matching(self, event_name_regex, check_error=True, timeout=None):
for ev in self.yield_matching(event_name_regex, check_error, timeout):
return ev
def yield_matching(self, event_name_regex, check_error=True, timeout=None):
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)
if rex.match(ev.name):
yield ev
def get_info_matching(self, regex):
rex = re.compile("(?:{}).*".format(regex))
while 1:
ev = self.get_matching("DC_EVENT_INFO")
if rex.match(ev.data2):
return ev
def wait_next_incoming_message(self):
""" wait for and return next incoming message. """
ev = self.get_matching("DC_EVENT_INCOMING_MSG")