Jump to content

infinite/too long execution problem


Salem

Recommended Posts

Hi. How can I disable aborting scripts on infinite/too long execution error, or maybe set longer time to executing? I have script which ends but it works about 10-20 seconds and it stops after few and I wish to not until I'll find better solution of the way its working. I know that such running script is lame but it run very rare and must be finished.

Link to comment

You can't disable the maximum execution time at MTA. Looping a piece of code for a long time immediately freezes the script execution and causes overwhelming CPU usage. There is no point in using loops in order to e.g. replace a timer.

Please post your source code so we might be able to find a more efficient solution for your problem.

Link to comment
  • Moderators

and try out getTickCount()

  
--Script can only executed every 1 second (tickcount is in milliseconds) 
local lastControlFire = 0 
function myFunction () 
  if 1000 - (getTickCount()-lastControlFire) < 0 then 
    lastControlFire = getTickCount() 
  end 
end 

Nice for add to gui buttons, or something that works on onClientRender or onClientPreRender. (No timers needed your onClientRender is your timer and will take real time, does not matter how much fps lagg you got. It will always be circa 1 second.)

Edited by Guest
Link to comment

Thanks for some suggestions, I'll think about it. The code is too complicated to post. The problem lies probably in the time of executing very database complicated query in a loop of several iterations plus loops for searching properties of world's objects (which can be large number indeedly). So my intention is not to change the code but rather to have possibilities to resume / continue the heavy execution, as I have mentioned above, it's only one in a longer time.

Anyway, thanks.

By the way, what you mean with 'return' IIYAMA above?

Executing every 1 second is useless, because the string of database queries is executing and I can't pause it. However i can try to pause in some loops.

Link to comment
  • Moderators
By the way, what you mean with 'return' IIYAMA above?

I had something else on my mind.

Executing every 1 second is useless, because the string of database queries is executing and I can't pause it. However i can try to pause in some loops.

Well maybe it is handy to use one timer to update some non important stats. Save it within the tables and update the database when the timer get executed.

Tables are still in the memory they can easy and fast be changed, but a database write directly/indirect on the hard drives.(as far I know) Unload the tables after you store the data.

Of course there can be a risk when the power falls off or crash. (with in this second)

Make sure you script will store the data after the resource stops.

It is just how I would do it. Probably some people are against it. Only slow data.

Link to comment

You can try using Lua coroutines. They are a nice way to pause the execution of function and resume it later. An example:

function infiniteLoopFunction() 
    local lastresume = getTickCount() 
    while true do 
        --do something 
  
        if getTickCount() > lastresume+200 then 
            coroutine.yield() 
            lastresume = getTickCount() 
        end 
    end 
end 
  
function resumeLoopThread() 
    coroutine.resume(loopThread) 
end 
  
loopThread = coroutine.create(infiniteLoopFunction) 
resumeLoopThread() 
setTimer(resumeLoopThread, 400, 0) 

This code will execute the infinite loop in the infiniteLoopFunction function, but will not cause the error. It runs the loop for 200 ms, then pauses for another 200 ms before resuming the loop again.

More about coroutines:

http://www.lua.org/pil/9.html

http://lua-users.org/wiki/CoroutinesTutorial

By the way, I used coroutines in my traffic resource to load the paths. It takes 8-9 seconds to load them on my older computer and the maximum execution time of the loop (unless you use certain functions) is 5 seconds. To avoid "too long execution" error, I put the loading code into the coroutine and the problem was solved :)

Edited by Guest
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...