diff --git a/circus/plugins/watchdog.py b/circus/plugins/watchdog.py index e48a07e8e..0d4aa74c2 100644 --- a/circus/plugins/watchdog.py +++ b/circus/plugins/watchdog.py @@ -48,6 +48,7 @@ class WatchDog(CircusPlugin): used when killing the processes """ name = 'watchdog' + plugin_name = 'plugin:' + name def __init__(self, endpoint, pubsub_endpoint, check_delay, ssh_server, **config): @@ -136,7 +137,9 @@ def _discover_monitored_pids(self): self.pid_status = dict() all_watchers = self.call("list") for watcher_name in all_watchers['watchers']: - if self._match_watcher_name(watcher_name): + # do not discover watchdog + if self._match_watcher_name(watcher_name) and \ + watcher_name != self.plugin_name: processes = self.call("list", name=watcher_name) if 'pids' in processes: for pid in processes['pids']: @@ -182,7 +185,7 @@ def _decode_received_udp_message(self, data): :return: decoded message :rtype: dict or None """ - result = re.match(self.msg_regex, data) + result = re.match(self.msg_regex, data.decode()) if result is not None: return result.groupdict() @@ -217,6 +220,9 @@ def look_after(self): max_timeout = self.loop_rate * self.max_count too_old_time = time.time() - max_timeout + # Instead of del in loop, that will cause exception in Python3, + # add to list and del from pid_status after loop. + pids_to_del = list() for pid, detail in self.pid_status.items(): if detail['last_activity'] < too_old_time: logger.info("watcher:%s, pid:%s is not responding. Kill it !", @@ -233,4 +239,6 @@ def look_after(self): # Trusting watcher to eventually stop the process after # graceful timeout - del self.pid_status[pid] + pids_to_del.append(pid) + for pid in pids_to_del: + del self.pid_status[pid] diff --git a/circus/tests/test_plugin_watchdog.py b/circus/tests/test_plugin_watchdog.py index a96ed6578..428de0eec 100644 --- a/circus/tests/test_plugin_watchdog.py +++ b/circus/tests/test_plugin_watchdog.py @@ -72,4 +72,5 @@ def test_watchdog_discovery_not_found(self): self.assertEqual(len(pid_status), 0, pid_status) yield self.stop_arbiter() + test_suite = EasyTestSuite(__name__)