From 8d26c8634d2677b4402f0a21b9ab8244b44640db Mon Sep 17 00:00:00 2001
From: Fabio Manganiello <info@fabiomanganiello.com>
Date: Thu, 9 Jun 2022 11:59:29 +0200
Subject: [PATCH] Keep the ntfy process in stop_wait state even when the plugin
 is configured with no subscriptions

---
 platypush/plugins/ntfy/__init__.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/platypush/plugins/ntfy/__init__.py b/platypush/plugins/ntfy/__init__.py
index df9735bc3..064275723 100644
--- a/platypush/plugins/ntfy/__init__.py
+++ b/platypush/plugins/ntfy/__init__.py
@@ -53,16 +53,13 @@ class NtfyPlugin(RunnablePlugin):
         self._ws_proc = None
 
     def _connect(self):
-        if self.should_stop():
+        if self.should_stop() or (self._ws_proc and self._ws_proc.is_alive()):
             self.logger.debug('Already connected')
             return
 
         self._ws_proc = multiprocessing.Process(target=self._ws_process)
         self._ws_proc.start()
 
-        while not self._should_stop.is_set():
-            self._should_stop.wait(timeout=1)
-
     async def _get_ws_handler(self, url):
         reconnect_wait_secs = 1
         reconnect_wait_secs_max = 60
@@ -125,6 +122,9 @@ class NtfyPlugin(RunnablePlugin):
         if self._subscriptions:
             self._connect()
 
+        while not self._should_stop.is_set():
+            self._should_stop.wait(timeout=1)
+
     def stop(self):
         if self._ws_proc:
             self._ws_proc.kill()