Logic Machine Forum
event based scripts continue to run even when they are disabled - 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: event based scripts continue to run even when they are disabled (/showthread.php?tid=1863)



event based scripts continue to run even when they are disabled - rocfusion - 26.01.2019

Hi,

Create virtual object.  Add the script below and run it.  Now wait until logs the first time.  Then disable the script.  It will continue to run in the background even though it should be disabled.    I would expect when you hit disabled it should kill off any running threads of the script.

thx 

Roger


Code:
mac="c0:48:e6:ee:d1:2f"

function sendWOL()
 --call the WOL
 local WOL = function(target)
   local dest_ip="255.255.255.255"
   local port=9
   local socket = require("socket")
   local udpwol = assert(socket.udp())
   udpwol:setoption('broadcast', true)
   clean_target = string.gsub(target,":","")
   clean_target = string.gsub(clean_target,"-","")
   hex_target = lmcore.hextostr(clean_target)
   payload = lmcore.hextostr("FFFFFFFFFFFF")
   for i=1,16 do
     payload = payload .. hex_target
   end
   assert(udpwol:sendto(payload, dest_ip, port))
 end
 WOL(mac)
 WOL(mac)
 WOL(mac)
 WOL(mac)
 WOL(mac)
 WOL(mac)
 sleep(1)
 WOL(mac)
 WOL(mac)
 WOL(mac)
 WOL(mac)
 WOL(mac)
 WOL(mac)
end

while true do
 log("running")
 sleep(150)
 sendWOL()
 log("sent wol")
end



RE: event based scripts continue to run even when they are disabled - admin - 28.01.2019

Event scripts should never have infinite loops. You should use a resident script instead together with script.enable/disable. The only way to kill a script like this is from System config / Status / Running processes.