Cancel event-scripts - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Cancel event-scripts (/showthread.php?tid=1893) |
Cancel event-scripts - buuuudzik - 08.02.2019 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. Maybe there is some more elegant way. RE: Cancel event-scripts - Daniel - 08.02.2019 Here Erwin is using os.kill() to stop the running PID https://forum.logicmachine.net/showthread.php?tid=1789&pid=11116#pid11116 RE: Cancel event-scripts - admin - 08.02.2019 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. Code: if not client then RE: Cancel event-scripts - buuuudzik - 08.02.2019 Thanks for replies Second solution is nice but how can I get pid in eventhandler? I have only an event object withou pid. RE: Cancel event-scripts - Daniel - 08.02.2019 You don't need PID as the point is to use resident script instead of event. RE: Cancel event-scripts - buuuudzik - 08.02.2019 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: Code: copas.addthread(function() RE: Cancel event-scripts - admin - 10.02.2019 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 RE: Cancel event-scripts - buuuudzik - 10.02.2019 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: -- event start 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. RE: Cancel event-scripts - admin - 11.02.2019 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. Code: if not client then RE: Cancel event-scripts - buuuudzik - 11.02.2019 Thank you admin for your effort. Maybe it will help also for other user which will search something similar. But for me it should be a parameter of event-scripts like "Execute on read". There should be 3 options: - unlimited (default), - only first, - only last. This would end using of semaphore and add this missed property of event script. RE: Cancel event-scripts - admin - 11.02.2019 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. RE: Cancel event-scripts - apkotelnikov - 12.02.2019 There is another option: -- At script begin script.disable(_SCRIPTNAME) -- some code -- at script end script.enable(_SCRIPTNAME) RE: Cancel event-scripts - buuuudzik - 13.02.2019 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: value = event.getvalue() 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 RE: Cancel event-scripts - admin - 13.02.2019 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. RE: Cancel event-scripts - JASK - 07.01.2023 (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. This script was nice It's it possible to have different sleep (delay) between each command? RE: Cancel event-scripts - khalil - 08.01.2023 (11.02.2019, 14:14)buuuudzik Wrote: Thank you admin for your effort. Maybe it will help also for other user which will search something similar. Hello Dear Admin Does the new firmware consider this in the event based script with the three options: Normal First instance only Last instance only RE: Cancel event-scripts - admin - 09.01.2023 @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. RE: Cancel event-scripts - JASK - 30.01.2023 (09.01.2023, 07:49)admin Wrote: @JASK, you can use scenes for this. You can set a custom delay after each command there. @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. RE: Cancel event-scripts - admin - 31.01.2023 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. |