Is there a way to cancel running events scripts e.g.
button for day scene and night scene which sends 0 or 1.
Every execute of command first cancel all instances of this script and after run new instances which run code.
Every script executes ~20 commands and waits 0.5s(pause between commands) or until one zone ends the motion. Whole scene continues a few minutes.
So I think this is something different from not allowing to start new same script by semaphore lock. I can save process id and then kill all existing processes which would be stored in some place but then probably there would be some problems with race condition.
Saving current PID might still lead to race conditions if two scripts execute in really short time period. The more elegant way is to use a resident script with two copas threads - one for bus monitoring and another for sequence.
I don't understand why it should has 2 threads, it looks like 2 servers. I thinked that it is because that 1st monitor a bus and deals with cancelling events and another receives adress and pid from events via udp which collects in tables.
I've commented this code and I don't recognize any change:
This is a single resident script for bus monitoring and sequence execution. If you provide a more detailed info on your task I can provide a better example
10.02.2019, 12:18 (This post was last modified: 10.02.2019, 12:20 by buuuudzik.)
I have reusable code for day/night scene which controls blinds. This scene doesn't run immediately but continues for e.g. 5 minutes, it depends on which zones are switched on and other conditions.
Above scenes are running by sun event and also by a user which can sent it one by one but the most important is the last and before it starts it should cancel all old instances.
Perfect solution would be:
Code:
123456
-- event startcancelOldInstances()
day = event.getvalue()
ifdaythenscenes.day() elsescenes.night() end
I think that possible option is also adding additional GA which would storage the newest event pid and in event I can check before every step if that event has same pid.
But this will add another unnecessary requests to DB, and adding unnecessary GA to project is also not good.
I think this is missed in events mechanism which is great. There is a possibility to not run new event which is currently running but there is no in same elegant way tell to LM that it should run only the newest instance.
But your mechanism is very, very good and in comparison to e.g. eibPort it is nice that in your solution there is no time limit for script.
Here's a complete example with two sequences - one for "on" event, another for "off". 32/1/1 is the object that triggers execution. Delay between each command is fixed at 0.5 seconds. This can be made adjustable via sequence table, but it must not be 0, otherwise sequence thread won't be able to pass control to localbus monitor thread.
Good suggestion, though semaphores still have to be used to prevent parallel execution and to create an event queue for things that require exclusive access like serial ports.
I've tested this code but it doesn't work, you can try in such way. Please create 2 objects "C1" and "C2".
"C1" should has such event script:
Code:
1234567891011
value = event.getvalue()
-- At script beginscript.disable(_SCRIPTNAME)
-- some codeos.sleep(5)
grp.update("C2", value)
-- at script endscript.enable(_SCRIPTNAME)
And please fast(<5s) send to "C1" 1 and 2.
"C2" should be changed only to 2, but is changed to 1 and isn't changed into 2. And this is little strange for me because I don't know why it isn't changed then into 2. Could you explain admin
This example is similar to using semaphores, it executes only the first instance. But it can still have race condition: if C1 is updated really fast (before script.disable happens) two instances will execute in parallel. Semaphores guarantee locking on OS level.
07.01.2023, 00:14 (This post was last modified: 07.01.2023, 00:14 by JASK.)
(11.02.2019, 12:45)admin Wrote: Here's a complete example with two sequences - one for "on" event, another for "off". 32/1/1 is the object that triggers execution. Delay between each command is fixed at 0.5 seconds. This can be made adjustable via sequence table, but it must not be 0, otherwise sequence thread won't be able to pass control to localbus monitor thread.
(09.01.2023, 07:49)admin Wrote: @JASK, you can use scenes for this. You can set a custom delay after each command there.
@khalil, new firmware has these 3 options for event script execution.
@admin
The commands don't seem to get interrupted when I use scenes. I thought about using this to control windows for ventilation when the thermostat is in cooling mode. 15 minute delay between when opening and 5 minutes when they close.
Scenes have a different behavior which might not suit your task. Scenes mapped to the same trigger address with a different value don't cancel each other.
You can use an event script in either "First instance only" or "Last instance only" mode instead.