Jump to content




Too long without yielding errors during file write


  • You cannot reply to this topic
8 replies to this topic

#1 civilwargeeky

  • Members
  • 393 posts

Posted 16 December 2013 - 11:41 PM

Hello. I am the coder for Variable Size Quarry, and recently I had a user come to me saying that my program errored during its backup file write with a "too long without yielding error." I have been told in the past that this happens most frequently on laggy servers, but I wanted to ask the pros if there is anything I can do.
The code for the function is here:
Spoiler
This function is being calledmost often from this function
Spoiler
I don't understand why the too long without yielding error is coming up. I am calling "sleep(0)" every time the turtle moves, because I was told that sleep calls "coroutine.yield()", but yet it still errors sometimes. So what could I do? I'm not too knowledgeable about coroutines and how they work internally. The parallel API is as far as I've needed to go.
Any help would be appreciated. Thank you for reading.

Edited by civilwargeeky, 16 December 2013 - 11:43 PM.


#2 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 16 December 2013 - 11:56 PM

My first guess would be that the handle to 'file' cannot be obtained because it there is another handle to it that hasn't been closed. If this is the case, then you would just be repeating the same loop infinitely super fast (no yielding) and thus this error would appear. So, I guess to fix it would just to be to handle the case that you couldn't save to that file.

#3 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 17 December 2013 - 12:12 AM

If sleep(0) isn't working, try this:
os.startTimer(0)
os.pullEvent("timer")
The timer ID handling really shouldn't matter, unless you are using timers elsewhere in your program. (I haven't looked at the code yet.)

#4 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 17 December 2013 - 12:43 AM

View Postawsmazinggenius, on 17 December 2013 - 12:12 AM, said:

If sleep(0) isn't working, try this:
os.startTimer(0)
os.pullEvent("timer")
The timer ID handling really shouldn't matter, unless you are using timers elsewhere in your program. (I haven't looked at the code yet.)

This is essentially the same thing as calling sleep(0) except for the timer ID handling that you mentioned. I don't see how this would change anything?

#5 civilwargeeky

  • Members
  • 393 posts

Posted 17 December 2013 - 12:47 AM

View PostGrim Reaper, on 16 December 2013 - 11:56 PM, said:

My first guess would be that the handle to 'file' cannot be obtained because it there is another handle to it that hasn't been closed. If this is the case, then you would just be repeating the same loop infinitely super fast (no yielding) and thus this error would appear. So, I guess to fix it would just to be to handle the case that you couldn't save to that file.
Hmm... Why would there be another file handle open though?
repeat
  file = fs.open(saveFile, "w")
until file
That should only make one file handle, as the file handle existing breaks the loop. I don't really see how it could continue looping.
And what do you mean by "handle the case that you couldn't save to file"? I don't think I'm able to check if the file was successfully closed (if thats what you're saying). Sorry, but I'm just a bit confused.

Edited by civilwargeeky, 17 December 2013 - 12:47 AM.


#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 17 December 2013 - 12:58 AM

If the file handle fails to open, you shouldn't just continue to stupidly bash your head against whatever problem is preventing it, you should read out the error message and get some user interaction. Maybe try it again after a moment, but don't just sit there looping trying to open the handle.

#7 civilwargeeky

  • Members
  • 393 posts

Posted 17 December 2013 - 01:04 AM

View PostLyqyd, on 17 December 2013 - 12:58 AM, said:

stupidly bash your head against whatever problem is preventing it
Ouch. That's not nice...

Regardless, point taken and thank you, I was unaware that fs.open even gave error messages. I will look into fixing it. Do you think that fixing that will solve the "too long without yielding error"? Or is there something else I should be doing that I'm not?

#8 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2013 - 01:25 AM

View Postcivilwargeeky, on 17 December 2013 - 01:04 AM, said:

I was unaware that fs.open even gave error messages.
Of course it does, about 80% of Lua functions do. The second return value is the error message when the first value is false or nil.

#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 17 December 2013 - 01:28 AM

View Postcivilwargeeky, on 16 December 2013 - 11:41 PM, said:

I am calling "sleep(0)" every time the turtle moves, because I was told that sleep calls "coroutine.yield()", but yet it still errors sometimes.
On that note, most of the commands in the turtle API also yield. The exceptions seem to be turtle.getItemCount(), turtle.getItemSpace(), and turtle.getFuelLevel().





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users