This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
BrolofTheViking's profile picture

Is there any way to get rid of the "too long without yielding" error?

Started by BrolofTheViking, 14 October 2012 - 10:40 PM
BrolofTheViking #1
Posted 15 October 2012 - 12:40 AM
I'm running a program that needs to call a loop numerous thousand times, but can't do so because computercraft is stopping it from running the loop for too long.
Is there anyway to circumvent this?
Shazz #2
Posted 15 October 2012 - 12:56 AM
Show us your code or else we can't help you.
Lyqyd #3
Posted 15 October 2012 - 01:11 AM
Try yielding. A sleep(0) in the loop should do.
BrolofTheViking #4
Posted 15 October 2012 - 01:28 AM
Sorry, wasn't exactly clear I guess
I'm not having a syntax error or anything like that, so I figured that, since this is a generic problem and not specifically related to my program, I wouldn't provide a code that would distract you, looking for syntax errors
Computercraft (or more likely, lua) has a built in thing where it stops infinite loops, by giving an error when a loop iterates too many times.
However, for what I'm doing, I need it to run an amount of times greater than the built in limit.

my code is this http://pastebin.com/FizscyHm
which then creates an 814 kilobyte long file (17,576 blocks). I can't make it record an area any larger than that one.
I believe that I may have misinterpreted the error. Rather than the problem being that the loop runs too far, I probably just gave the write() function too much.

However, the question still stands: Is it possible to get past the recursion limit built into Lua?
PixelToast #5
Posted 15 October 2012 - 01:33 AM
Sorry, wasn't exactly clear I guess
I'm not having a syntax error or anything like that, so I figured that, since this is a generic problem and not specifically related to my program, I wouldn't provide a code that would distract you, looking for syntax errors
Computercraft (or more likely, lua) has a built in thing where it stops infinite loops, by giving an error when a loop iterates too many times.
However, for what I'm doing, I need it to run an amount of times greater than the built in limit.

my code is this http://pastebin.com/FizscyHm
which then creates an 814 kilobyte long file (17,576 blocks). I can't make it record an area any larger than that one.
I believe that I may have misinterpreted the error. Rather than the problem being that the loop runs too far, I probably just gave the write() function too much.

However, the question still stands: Is it possible to get past the recursion limit built into Lua?
removing the yielding error has been asked before, and it will not happen

and wait, recursion limit? that has nothing to do with yielding errors xD
Fatal_Exception #6
Posted 15 October 2012 - 01:58 AM
It's a timeout error, not a recursion limit. Literally, it's been too long since you've given another process the chance to run. Your program is not playing nice in a co-operative multitasking environment, so it's been sent to sit in the corner.

The solution is as Lyqyd said. Throw in some sleep(0) to let it yield.
BrolofTheViking #7
Posted 15 October 2012 - 02:04 AM
Ah, I see. Well, I misinterpreted that then, I assumed that it was something similar to what I had seen in other languages. Another stupid point for me today, damnit.
remiX #8
Posted 15 October 2012 - 01:44 PM
If i may ask, how does sleep(0) help? Doesn't it make it sleep for 0 seconds which is nothing? Just curious
GopherAtl #9
Posted 15 October 2012 - 01:53 PM
You have to understand how cooperative multitasking works. Most things these days use preemptive multitasking, meaning some control process forcibly ends one thread to let others run. Cooperative multitasking doesn't do this; each process has to yield before the next one can run. Any functions that wait for something - pullEvent, sleep, rednet.receive, many of the turtle functions - wait by yielding until some event happens. This is what sleep(0) does - it yields, so any other tasks can run. Sleeping for 0 just means it will resume as soon as its turn comes up again, where sleep(5) would not resume until at least 5seconds have passed.
remiX #10
Posted 15 October 2012 - 01:56 PM
That's pretty awesome.