Logic Machine Forum
Script run prevention - 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: Script run prevention (/showthread.php?tid=4064)



Script run prevention - judgment - 28.05.2022

Hello all, how i could prevent to run event script if it is already in process? 
thank you


RE: Script run prevention - admin - 30.05.2022

See this example: https://forum.logicmachine.net/showthread.php?tid=2611&pid=16762#pid16762
Change the timeout from 5 seconds to 0.1


RE: Script run prevention - judgment - 30.05.2022

(30.05.2022, 06:38)admin Wrote: See this example: https://forum.logicmachine.net/showthread.php?tid=2611&pid=16762#pid16762
Change the timeout from 5 seconds to 0.1

thanks for advice. it seams that semaphore doesn't starts even with simple code below i receiving log error* arg: 
Code:
require('sem')
stat, err = sem.runlocked('eventlock', 0.1, function(lockres)
  
end)

if stat then
  log('ok')
else
  log('error', err)
end



RE: Script run prevention - admin - 31.05.2022

stat, err are assigned to what the function returns. Since your function does not return anything stat and err are nil and you get empty "error" entry in Logs.

Use this example and put your actual script code inside of the scriptfn function. In the current state this example will simply block execution of any other instances of the same script for 10 seconds. It will also propagate any errors from scriptfn so they are visible in the Error log.
Code:
require('sem')

function scriptfn()
  log('script start')
  os.sleep(10)
  log('script end')
end

stat, err = sem.runlocked('eventlock', 0.1, function(lockres)
  if lockres then
    return pcall(scriptfn)
  else
    return nil, 'lock failed'
  end
end)

if not stat then
  error(err)
end