Quit process that takes too long

Hello,

I made command that works in the loop - finds and unrolls the largest surface within each polysurface, but the command sometimes hangs ( rhino becomes non-responsive ) during the process.

I can “catch” the error when unroll method fails but how to catch it when it hangs
Idea is to give it ~10 sec time to do it and terminate it if it does not finish (success or fail) in that period, and go to the next polysurface
At the moment I work in python but I plan to move to VB Rhinocommon anythow so any idea/solution is welcome

Thanks in advance
Aleksandar

@AleksandarSM,

if you’re sure that your script is stuck in the loop and not a rhino command, you may use something like below. You can still cancel with ESC or define a duration when the script exits the loop.

import time
import scriptcontext
import rhinoscriptsyntax as rs
    
def DoSomethingForSomeTime():
    
    start_time = time.time()
    duration = 5 #seconds
    counter = 0
    
    while True:
        if scriptcontext.escape_test(False):
            print "Canceled with ESC"
            return
    
        elapsed_time = time.time() - start_time
        if elapsed_time >= duration:
            print "Canceled after {} seconds".format(elapsed_time)
            return
        
        rs.Prompt(str(counter))
        counter += 1
    
DoSomethingForSomeTime()

Note that i added rs.Prompt(str(counter)) just so you can see the loop is still running. If you remove this and the counter the time measured is more accurate.

c.

Hello Clement,

It is actually a rhino command that virtually hangs the loop.

when I have some “complex” parts (solids), Rhino seems to hangs while trying to perform scripted “squish” or while trying to calculate volume or center of gravity for this parts…

I prefer to detect such parts, re-model them in order to make them it more simple, and then re-run the script…

Aleksandar