fix memory leak in jeedom_com & small code quality improvment #69
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR aim to fix the memory leak observed on deb11. I cannot explain why it didn't happen on others versions.
It was due to the fact that the "send async thread" was creating new thread for each new cycle (from 0.3s for most of the plugin to 30s for some like plugin-sms); and that's why the issue had small of huge impact: it depends the plugin cycle config.
So "send async thread 1" creates "send async thread 2" which will create "send async thread 3" etc; meaning that potentially none of this thread ever stop until the very last one stops which happen only when daemon is stopped; so the daemon continuously create new thread and which consume additional memories.
The correct way to do this is to have one and only one thread which will run forever until the daemon stop. To make sure the thread is stopped when the parent process (the daemon) is stopped, we flag that thread as a "daemon thread" = never-ending background task.
I took the opportunity to clean a bit the rest of the code as well.
===
to fix issue in each plugin, in theory we just need to copy/past the new version of jeedom.py to the plugin BUT we should first check if there wasn't any local changes made
===
Suggested changelog entry
None.
Related issues/external references
Fixes #
Types of changes
PR checklist