From 0d9c53c4ec182c6bf3452506351258b61bb1f739 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 8 Jul 2015 16:15:09 -0300 Subject: [bug] prevent logbook subscriber to fail Fix: If the logbook controller is not started the stop call will fail. Trying to start it twice fails. --- changes/bug-7273_logbook-subscriber-start | 2 ++ src/leap/bitmask/logs/utils.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 changes/bug-7273_logbook-subscriber-start diff --git a/changes/bug-7273_logbook-subscriber-start b/changes/bug-7273_logbook-subscriber-start new file mode 100644 index 00000000..976d2f35 --- /dev/null +++ b/changes/bug-7273_logbook-subscriber-start @@ -0,0 +1,2 @@ +- Closes bug #7273 - ZMQError: address already in use - logbook subscriber already started. +- Closes bug - logbook subscriber stop fails if not started. diff --git a/src/leap/bitmask/logs/utils.py b/src/leap/bitmask/logs/utils.py index f0e820b2..683fb542 100644 --- a/src/leap/bitmask/logs/utils.py +++ b/src/leap/bitmask/logs/utils.py @@ -188,15 +188,17 @@ class QtLogHandler(logbook.Handler, logbook.StringFormatterHandlerMixin): class _LogController(object): def __init__(self): self._qt_handler = QtLogHandler(format_string=LOG_FORMAT) + self._logbook_controller = None self.new_log = self._qt_handler.qt.new_log def start_logbook_subscriber(self): """ Run in the background the log receiver. """ - subscriber = ZeroMQSubscriber('tcp://127.0.0.1:5000', multi=True) - self._logbook_controller = subscriber.dispatch_in_background( - self._qt_handler) + if self._logbook_controller is None: + subscriber = ZeroMQSubscriber('tcp://127.0.0.1:5000', multi=True) + self._logbook_controller = subscriber.dispatch_in_background( + self._qt_handler) def stop_logbook_subscriber(self): """ @@ -205,8 +207,10 @@ class _LogController(object): This allows us to re-create the subscriber when we reopen this window without getting an error at trying to connect twice to the zmq port. """ - self._logbook_controller.stop() - self._logbook_controller.subscriber.close() + if self._logbook_controller is not None: + self._logbook_controller.stop() + self._logbook_controller.subscriber.close() + self._logbook_controller = None def get_logs(self): return self._qt_handler.logs -- cgit v1.2.3