From 56c7258c74eba78928fa4edd7e9dfbb5255be77e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 10 Jan 2019 23:08:29 +0100 Subject: [PATCH] Setting names for threads --- platypush/backend/__init__.py | 2 ++ platypush/backend/camera/pi.py | 3 ++- platypush/backend/http/__init__.py | 4 +++- platypush/backend/http/request/__init__.py | 2 +- platypush/backend/mqtt.py | 4 +++- platypush/backend/music/snapcast.py | 4 +++- platypush/backend/tcp.py | 2 +- platypush/event/hook.py | 4 +++- platypush/plugins/light/hue/__init__.py | 4 +++- 9 files changed, 21 insertions(+), 8 deletions(-) diff --git a/platypush/backend/__init__.py b/platypush/backend/__init__.py index 3aafa7ee6..34da89194 100644 --- a/platypush/backend/__init__.py +++ b/platypush/backend/__init__.py @@ -44,6 +44,8 @@ class Backend(Thread): :type kwargs: dict """ + super().__init__(name='PlatypushBackend_' + self.__class__.__name__) + # If no bus is specified, create an internal queue where # the received messages will be pushed self.bus = bus or Bus() diff --git a/platypush/backend/camera/pi.py b/platypush/backend/camera/pi.py index 7c419a015..2e595cb75 100644 --- a/platypush/backend/camera/pi.py +++ b/platypush/backend/camera/pi.py @@ -145,7 +145,8 @@ class CameraPiBackend(Backend): return self.logger.info('Starting camera recording') - self._recording_thread = Thread(target=recording_thread) + self._recording_thread = Thread(target=recording_thread, + name='PiCameraRecorder') self._recording_thread.start() diff --git a/platypush/backend/http/__init__.py b/platypush/backend/http/__init__.py index 7ac371d68..b9a9df7bc 100644 --- a/platypush/backend/http/__init__.py +++ b/platypush/backend/http/__init__.py @@ -455,7 +455,9 @@ class HttpBackend(Backend): self.logger.info('Initialized HTTP backend on port {}'.format(self.port)) webserver = self.webserver() - self.server_proc = Process(target=webserver.run, kwargs=kwargs) + self.server_proc = Process(target=webserver.run, + name='PlatypushWebServer', + kwargs=kwargs) self.server_proc.start() if not self.disable_websocket: diff --git a/platypush/backend/http/request/__init__.py b/platypush/backend/http/request/__init__.py index feebd94e9..968c94ecf 100644 --- a/platypush/backend/http/request/__init__.py +++ b/platypush/backend/http/request/__init__.py @@ -77,7 +77,7 @@ class HttpRequest(object): self.logger.warning('Encountered an error while retrieving {}: {}'. format(self.args.url, str(e))) - Thread(target=_thread_func).start() + Thread(target=_thread_func, name='PlatypushHttpPoll').start() def get_new_items(self, response): diff --git a/platypush/backend/mqtt.py b/platypush/backend/mqtt.py index ea5638517..fc0246531 100644 --- a/platypush/backend/mqtt.py +++ b/platypush/backend/mqtt.py @@ -121,7 +121,9 @@ class MqttBackend(Backend): return if isinstance(msg, Request): - threading.Thread(target=response_thread, args=(msg,)).start() + threading.Thread(target=response_thread, + name='PlatypushMQTTResponseProcessor', + args=(msg,)).start() super().run() client = mqtt.Client() diff --git a/platypush/backend/music/snapcast.py b/platypush/backend/music/snapcast.py index 2cc3d717a..772fa7903 100644 --- a/platypush/backend/music/snapcast.py +++ b/platypush/backend/music/snapcast.py @@ -198,7 +198,9 @@ class MusicSnapcastBackend(Backend): for i, host in enumerate(self.hosts): port = self.ports[i] self._threads[host] = threading.Thread( - target=self._client(host, port)) + target=self._client(host, port), + name='PlatypushSnapcastWorker' + ) self._threads[host].start() diff --git a/platypush/backend/tcp.py b/platypush/backend/tcp.py index b5a7faf1d..23c48d9c2 100644 --- a/platypush/backend/tcp.py +++ b/platypush/backend/tcp.py @@ -88,7 +88,7 @@ class TcpBackend(Backend): finally: sock.close() - threading.Thread(target=_f_wrapper).start() + threading.Thread(target=_f_wrapper, name='PlatypushTCPListener').start() def run(self): super().run() diff --git a/platypush/event/hook.py b/platypush/event/hook.py index c7314e9e3..467927ed7 100644 --- a/platypush/event/hook.py +++ b/platypush/event/hook.py @@ -157,7 +157,9 @@ class EventHook(object): if result.is_match: logger.info('Running hook {} triggered by an event'.format(self.name)) - threading.Thread(target=_thread_func, args=(result,)).start() + threading.Thread(target=_thread_func, + name='PlatypushEventHook_' + self.name, + args=(result,)).start() # vim:sw=4:ts=4:et: diff --git a/platypush/plugins/light/hue/__init__.py b/platypush/plugins/light/hue/__init__.py index 8536e70d8..9d8be2d37 100644 --- a/platypush/plugins/light/hue/__init__.py +++ b/platypush/plugins/light/hue/__init__.py @@ -719,7 +719,9 @@ class LightHuePlugin(LightPlugin): lights = self.lights self.stop_animation() - self.animation_thread = Thread(target=_animate_thread, args=(lights,)) + self.animation_thread = Thread(target=_animate_thread, + name='PlatypushLightHueAnimate', + args=(lights,)) self.animation_thread.start()