Skip to content

Commit

Permalink
DBus client: remove watchdog
Browse files Browse the repository at this point in the history
Watchdog was initially used to diagnose a race condition in paho
that was worarounded by serialising everything on a single thread.
So no the deadlock fire just when an error happen during the connection
that just create a false alarm.

Just remove it as useless.
  • Loading branch information
GwendalRaoul authored and Pedro Silva committed Jul 8, 2019
1 parent c48226b commit 12fbed5
Showing 1 changed file with 1 addition and 88 deletions.
89 changes: 1 addition & 88 deletions python_transport/wirepas_gateway/dbus/dbus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,11 @@
from pydbus import SystemBus
from gi.repository import GLib, GObject
from .sink_manager import SinkManager
from threading import Thread, enumerate, currentThread
from time import sleep
from threading import Thread
import logging
import sys
import dbusCExtension


class DBusWatchdog(Thread):
"""
Watchdog to monitor DBus infinite loop managed by GLib
"""

def __init__(self, logger, watchdog_period_s=1):
"""
Init function
:param watchdog_period_s: period to reset the watchdog
from the GLIB loop
"""
Thread.__init__(self)

# logger
self.logger = logger

# Period to check for watchdog on this thread.
# It means that if the watchdog was not reseted
# during 3 watchdog period from GLIB loop
# the deadlock is detected
self.check_watchdog_period = 3 * watchdog_period_s

# Daemonize this thread to be exited with the process
self.daemon = True
self.running = False
self.watchdog = False

# Schedule the reset function to be scheduled every watchdog_period_s
# from GLIB loop. If loop is locked (that should never happen in normal
# situation), the watchdog will not be reseted anymore.
GObject.timeout_add_seconds(watchdog_period_s, self._reset_watchdog)

def run(self) -> None:
"""
Thread infinite loop to periodicaly check the watchdog status
:return:
"""
self.running = True
while self.running:
sleep(self.check_watchdog_period)
if self.watchdog:
# Watchdog was not reseted by GLIB loop
self.logger.error("Deadlock detected")

# Add more traces to understand what other threads are doing
for thread in enumerate():
if thread.name is self.name:
# Skip current Thread
continue

self._print_thread_info(thread)

# Re-arm the watchdog
self.watchdog = True

def _print_thread_info(self, thread) -> None:
self.logger.error(
" Thread name: {} - Alive={} ".format(thread.name, thread.is_alive())
)
frame = sys._current_frames().get(thread.ident, None)
if frame:
self.logger.error(
"\t{} {} {}".format(
frame.f_code.co_filename,
frame.f_code.co_name,
frame.f_code.co_firstlineno,
)
)
else:
self.logger.error("\tNo frame available")

def _reset_watchdog(self):
self.watchdog = False
# Return true to reschedule the callback from GLib loop
return True

def stop(self):
self.running = False


class DbusEventHandler(Thread):
"""
Dedicated Thread to manage DBUS messages signals in C
Expand Down Expand Up @@ -134,10 +52,6 @@ def __init__(self, logger=None, c_extension=True, ignored_ep_filter=None, **kwar
# logger
self.logger = logger or logging.getLogger(__name__)

# watchdog
self.watchdog = DBusWatchdog(self.logger)
self.watchdog.start()

# Main loop for events
self.loop = GLib.MainLoop()

Expand Down Expand Up @@ -244,7 +158,6 @@ def run(self):
self.loop.run()
except KeyboardInterrupt:
self.loop.quit()
self.watchdog.stop()

self.on_stop_client()

Expand Down

0 comments on commit 12fbed5

Please sign in to comment.