Timeout for Ruby Scripts
-
I am experimenting with a way to pause running scripts, and this is what I have so for. I don't have all that deep of an understanding of threads, so if this is going in the wrong direction, let me know.
Please try this out if you have time. You will likely need to adjust the count and timeout variables for your system.
I don't know what kind of performance penalty using the thread variable imposes, but it sure is nice to have a progress report as you go; and could easily show an estimated time for completion.
Eventually, I would like to make this transparent by providing a simple wrapper for making the call, and integrating into start_operation/commit_operation/abort_operation.
model = Sketchup.active_model entities = model.entities count = 10000 timeout = 3 # seconds thr1 = Thread.new { z = 0 count.times do |i| Thread.current[;i] = i x = i + 1 p1 = [0, 0, z] p2 = [x, 0, z] p3 = [x, x, z] p4 = [0, x, z] entities.add_face p1, p2, p3, p4 end } while thr1.alive? thr1.join(timeout) break unless thr1.alive? # model.active_view.invalidate if( UI.messagebox("#{thr1[;i]} of #{count} complete.\n\nContinue?", MB_YESNO) == IDNO ) Thread.kill thr1 end end
-
I am getting the same sort of increasing slow-downs as Chris was asking about. The time between each pause increase the more geometry is added.
-
Grrr thats annoying. Is it messing up the ability of the timer to work right?
-
Does it help taking out the garbage? Using that GC trick?
-
I don't think so, it is more a limitation of SU openGL architecture than ruby.
-
@jim said:
I am getting the same sort of increasing slow-downs as Chris was asking about. The time between each pause increase the more geometry is added.
Oops, not quite. I was creating and exploding groups when I wrote the above. When I just add plain geometry, the timeout appears to work alright.
But... the pause between when my dialog is visible and when it actually becomes click-able is getting longer.
I think I'm beating a dead horse.
Advertisement