-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If Rule is edited, get multiple instances of rule running #80
Comments
Here is some more info: I had an error in a rule. I fixed the error, saved the rule file, and tested again. This is what I got:
You can see that I set After restarting HABApp, this goes away:
What this means is that I have to remember to restart HABApp every time i change a rule, otherwise I get the old and new behavior (sometimes), and if it's a bug, the bug still happens (even though it's fixed), because the old rule is still running - which is confusing to say the least. This mostly seems to happen after an error in a rule. I assume this is not what is intended to happen? |
Do you see in the |
It's a bit hard to tell if the rule gets unloaded, as when you restart HABApp, it deletes the log file. I'll let you know if I figure it out. |
Do you observe the same issue with 0.10? |
Yes the logs are now retained, and yes I still get the same duplication issue. I just restart HABapp to stop it. Seems to mostly happen after an error, but I haven’t investigated in detail yet.
I’ll let you know if I figure it out.
Nick Waterton P.Eng
Sent from my iPhone
On Nov 2, 2019, at 12:21 AM, spacemanspiff2007 <notifications@github.com> wrote:
Do you observe the same issue with 0.10?
The logs should get rotated there instead of deleted.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#80?email_source=notifications&email_token=ACYJIZ7XLQRVIYXYHYKHBM3QRT54XA5CNFSM4I7APH22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC4TOSY#issuecomment-549009227>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACYJIZ4NZGJQVWFTQLXOM7TQRT54XANCNFSM4I7APH2Q>.
Unsubscribe from GE's commercial electronic messages: http://sc.ge.com/*casl-unsubscribe
Désabonner des messages électroniques commerciaux de GE: http://sc.ge.com/*lcap-desabonnement
|
Could you provide a (faulty) rule so I can reproduce it? |
Here is a (filtered) log for my miniRemote rule. The top section is normal. If I make no changes to the rule, and save it again, the lower section is what I get:
I've attached the The rule is this:
This is a new rule file I just created yesterday, so it's WIP, there are a lot of things i can simplify, I'm just getting it working, before I prettify it. This involves a lot of changes, and I have to restart HABApp every time i save the file. Any Idea why it duplicates all the time? |
I tried to reproduce it but failed because I am missing most of the item configurations. If you take a look at the provided log:
The first line is the event trigger and it only happens once which means that from the HABApp triggers everything is ok. class miniRemote_BackGarden(miniRemote):
def __init__(self, remote, *targets):
super().__init__(remote, *targets)
self.parent = self # <-- and this: if self.parent is None:
func = globals().get(target, None) # <--
else:
func = getattr(self.parent, target) # <-- shows that you are doing things fundamentally wrong and one of these parts is propably the cause of the error. There is never a reason to use I'm pretty sure if you restructure your code properly the problems will go away. |
This is not the only rule that has this issue, this rule was just the one I had created that day. Why would I not need to use
I have reduced the rule to this:
For testing, and it still duplicates the actions:
Where I change the output text, save and test again. The output textt changes in the last line:
But not in the previous lines, so it seems that some previous instances of the rule are still running. This changes from test to test, sometimes I get 3 outputs, sometimes I get 5, sometimes 3 of them change, and the rest don't. Example:
Looking at the log, I can see where the file is unloaded, but then it gets reloaded 4 times. is that normal?
The rule is stripped down to the minimum, not sub classed, not passing instances, not using |
Just some general hints: Also this for item in self.watch_items:
item = self.prefix + self.remote + item
try:
self.item[item] = Item.get_item(item)
self.listen_event(self.item[item], self.update_received, ItemStateEvent)
except HABApp.core.Items.ItemNotFoundException:
pass can be changed to this (just so there is increased readablity and it distinguishes between item and item names) for button in self.watch_items:
item_name = self.prefix + self.remote + button
self.item[item_name] = Item.get_create_item(item_name)
self.listen_event(item_name, self.update_received, ItemStateEvent) Anyway:
No - this is not normal. I am missing the unload section since if the rule is loaded it should also be unloaded. Is this not the case? Could you add the following rule in a new rule file? import logging
from threading import Lock
log = logging.getLogger('HABApp.AllRules')
lock = Lock()
class LogAllRules(HABApp.Rule):
def __init__(self):
super().__init__()
self.run_soon(self.show_rules)
def show_rules(self):
with lock:
log.info('-' * 120)
for r in self.get_rule(None):
log.info(f'{r.rule_name}')
LogAllRules() It will log the names of all running rules. If the rules are still running it should be easy to spot duplicate names. Can you show the output? |
Thanks for the logging comments, but if you notice the name of the rule is included in the log, so I just filter by tailing the log through Here is the output of your logging rule when HABApp is restarted
After editing a rule file a few times (and having it duplicate) - here is the output of the rule (
the log rule now outputs this:
Which looks no different. I am thinking that you may be right about caching of rules. I have some rules that I am using as general purpose utilities. For Example I would try using the here is the rule that is generating the duplicate output shown above:
and here is
I can see that it gets unloaded once, then reloaded 4 times when it is edited and saved. |
There are two possibilities to share: In your case I would create a rule file aeon_sensor with a AeonSensor class and create a rule for each sensor. That way it's wrapped properly and you can then use |
Looking into the mysterious behavior more, I have found that if I If, however, I edit the file (with any editor) whether or not I make any changes to the file, the file gets unloaded and then loaded anywhere from 2 to 4 times, ie, one unload, but 2-4 loads. I have This behavior may be file system dependent, so it might not happen on Windows, say. I'm running on Ubuntu 18.04 so its an ext4 file system. |
Yes, I am aware that there might be multiple loads, however I check and unload the file if it is already loaded. def request_file_load(...)
....
# Unload if we have already loaded
if path_str in self.files:
self.request_file_unload(event) So even if there are multiple load requests the file should always get unloaded first. The only other reason I can think if is an uncaught threading issue but then it should be more random (imho). Could you please post an side-by-side of the corresponding file events from |
Not sure what you are asking for. I've uploaded logs that show one unload event, followed by 2-4 load events. So it actually happens. You have no logging in the Can you give me specifics? |
So, here is what I have found. (I added some logging)
However, the other The root cause of this is one of:
Here is my log of this happening (I added the
This is my crude fix:
Tested and working. No more duplication in logs/multiple rules running etc. |
I suspected this might be the problem, guess I'll make loading and unloading completely blocking. |
I downloaded your latest version. The fix for this issue is quite complicated. It also causes a file to be unloaded and reloaded four times one after the other for each change in the file. Would it not be better to simply use a |
I may be wrong, but it seems if I edit a rule, and save it, then I end up with multiple instances of the rule running.
If i restart HABApp, then everything is OK.
I noticed this, when I'm using
I edited and saved the rule, then I started getting two messages in the log file, for the same event.
It doesn't do it every time, only if I make a major change in the file (like delete an rule, or add a listener).
Also, is there any difference between
ItemStateChangedEvent
andValueChangeEvent
? I seem to get two triggers forValueChangeEvent
sometimes, but only one forItemStateChangedEvent
(but this could just be part of the same issue described above).I'm still learning how to use your library, so I'm revising rules a lot, and this seems to become an issue (fixed by a restart so not a huge deal).
I have three rules files currently, could this be part of the issue?
Thanks,
The text was updated successfully, but these errors were encountered: