I'm pretty sure this isn't a bug with my code. There are no long running loops without either sleep() or os.pullEvent(), and all the programs run fine if i don't pause the game.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
[1.481] [SSP] Pausing the game causes random "Too long without yielding" errors
Started by bdew, 06 January 2013 - 02:38 AMPosted 06 January 2013 - 03:38 AM
This happens in SSP only, if i pause the game for a long period of time, after i unpause some of my computers/turtles crash with a "Too long without yielding" error.
I'm pretty sure this isn't a bug with my code. There are no long running loops without either sleep() or os.pullEvent(), and all the programs run fine if i don't pause the game.
I'm pretty sure this isn't a bug with my code. There are no long running loops without either sleep() or os.pullEvent(), and all the programs run fine if i don't pause the game.
Posted 06 January 2013 - 06:57 AM
This happens in SSP only, if i pause the game for a long period of time, after i unpause some of my computers/turtles crash with a "Too long without yielding" error.
I'm pretty sure this isn't a bug with my code. There are no long running loops without either sleep() or os.pullEvent(), and all the programs run fine if i don't pause the game.
For every "while true do" or other infinite loop, insert sleep(0) at the top of the loop. Too long without yielding meant that the computer was running "too long" without pulling/yielding events. The sleep function starts a timer (which uses os.pullEvent()), and therefore will fix this bug.
Posted 06 January 2013 - 09:19 AM
If you pause the game for a long time and your computer or Tuttle is running a program it's stopping that program in the middle of running thus "too long without yielding" error
Posted 06 January 2013 - 10:46 AM
For every "while true do" or other infinite loop, insert sleep(0) at the top of the loop. Too long without yielding meant that the computer was running "too long" without pulling/yielding events. The sleep function starts a timer (which uses os.pullEvent()), and therefore will fix this bug.
Most of my programs are built around an event dispatch loop, and there are sleep() or pullEvent() calls in all the apropriate places.
Also as i said they run fine if the game is unpaused and in smp.
If you pause the game for a long time and your computer or Tuttle is running a program it's stopping that program in the middle of running thus "too long without yielding" error
Well yeah, and that's a bug. Running around restarting programs every time i alt-tab out for a few minutes is getting old fast
Imho pausing the game should also pause that "too long without yielding" timer.
Of if that's too complicated we could have an option for SSP to disable that check entirely (the check from what i understand is more to prevent people overloading servers with bad code and busy waiting)
Posted 06 January 2013 - 02:42 PM
As a temporary workaround, you will not pause the game when alt-tabbing if you have any GUI open (including chat), or if you've used F3+p to toggle it.Well yeah, and that's a bug. Running around restarting programs every time i alt-tab out for a few minutes is getting old fast
Imho pausing the game should also pause that "too long without yielding" timer.
Of if that's too complicated we could have an option for SSP to disable that check entirely (the check from what i understand is more to prevent people overloading servers with bad code and busy waiting)
Posted 07 January 2013 - 01:52 PM
I was not aware of the F3+p hotkey, Thank you very much immibis.
Also this is certainly a bug, and sleep(0) would yeild until an event occured, I believe there is always some timer going on in the background, but by some chance if there wasn't any timers and no rednet and no key presses, this would halt forever and never do anything I believe ( I'm 90% sure that is how the consumer/producer system works in Lua ), so sleep(0) isn't a valid fix.
Also this is certainly a bug, and sleep(0) would yeild until an event occured, I believe there is always some timer going on in the background, but by some chance if there wasn't any timers and no rednet and no key presses, this would halt forever and never do anything I believe ( I'm 90% sure that is how the consumer/producer system works in Lua ), so sleep(0) isn't a valid fix.
Posted 07 January 2013 - 03:59 PM
sleep(0) sets a timer for 0 seconds in the future, then calls os.pullEvent until the timer expires, which has the effect of discarding any unprocessed events, yielding, and then returning immediately without a significant delay.
os.pullEvent yields until an event occurs.
os.pullEvent yields until an event occurs.
Posted 07 January 2013 - 05:59 PM
F3+p doesn't seem to be doing anything for me, but i found a simpler workaround - converting the game into lan mode makes it not pause when alt-tabed/
Posted 07 January 2013 - 06:46 PM
It doesn't have any visible effect until you alt-tab after you do it. But that works too.F3+p doesn't seem to be doing anything for me, but i found a simpler workaround - converting the game into lan mode makes it not pause when alt-tabed/