Jump to content

Updateticker in TOPs - Timed Service-Like Loop [fixed]


m-egger

Recommended Posts

Heyya,

I'm currently developing our project-internal filecache node with a couple of fancy features for usability / productivity.

The current workflow is starting a seperate Houdini instance with Juraj Tomori's Tool here: Background Render

Now I also wrote a couple of scripts that update the progress of the currently ongoing cache by analyzing the output directory and showing the progress. (as well as some info on the output like time per frame and size). [This was primarily developed for the use within a TOPs-Render network, however, the background process variant turned out to be much superior for a variety of reasons.]

Now what I built was a script in a seperate TOP-Network which is supposed to execute this analysis every couple of seconds for a given amount of time using the time.sleep(t) function.

Now usually this does exactly what I want, keeping this process/sleeping in the BG and execute the analysis function while Houdini stays functional. However, the problem is that sometimes (quite unpredictably, but mostly when aborting/refreshing this TOP-network) this sleeping switches to the foreground, causing Houdini to freeze for however long the ticker was set. And this is game-breaking when you sometimes have to wait for five minutes. You get the point.

Here is the (admittedly clumsy) bulk of code:

 

import time
import hou
import os

PARENT = hou.node("../../..")
ticker_s = PARENT.parmTuple("ticker_s").eval()
break_at_end = 0

node = hou.node("../../../mnp_cacher")
fstart = node.parm("f1").eval()
fend = node.parm("f2").eval()
totalframes = int(fend - fstart)

dir = PARENT.parm("outputfile").eval()
dir = os.path.dirname(dir)

def outputchecker(dur=20, tick=1, confirm=1):
    iterations = dur / tick
    
    warning_message = "Starting updateticker for {} seconds.".format(dur)
    if hou.ui.displayConfirmation( warning_message ):
        i=0
        while i < iterations:
            i += 1
            
            #print "Iteration: " + str(i)
            
            #SCAN OUTDIR LOCAL CODE ----------------------------
            counter = 0;
            duration_list = [0]
            folder_size = 0
            for (path, dirs, files) in os.walk(dir):
                for file in files:
                    if ".hip" in file: #exception for backup
                        #print str(counter) + ": SKIPPING"
                        continue
                    
                    filename = os.path.join(path, file)
                    folder_size += os.path.getsize(filename) # --- GET FOLDER SIZE
                    mytime = os.path.getmtime(filename) # --- GET CACHE TIME
                    
                    counter += 1
                    if counter==1:
                        counter
                        #print str(counter) + ": EXCEPT"
                    else:
                        prevtime = os.path.getmtime(filename_prev)
                        myduration = mytime - prevtime
                        #print str(counter) + " - " + str(mydur)
                        if myduration > 0:
                            duration_list.append(myduration)
                    filename_prev = filename
            #------------------------------------------------------------- scan end  
          
            frame = fstart + (counter-1)
            
            allframes = fend-fstart
            curframes = frame-fstart
            progress = curframes/allframes
            percent = "{:.0%}".format(progress)
                    
    
            # ----- SCAN OUTDIR AND UPDATE COMMENT
            scan = PARENT.hdaModule().scan_outdir(dir, 1)
            
            #print message
            running_message = ""
            running_message = "CACHING: {} (Fr.: {} / {})\n".format(percent, int(frame), int(fend))
            running_message += scan
            running_message += "      [Update Ticker: {} / {}]\n".format(i, iterations)
            
            PARENT.setComment(running_message)
            time.sleep(tick)
        

outputchecker(ticker_s[0], ticker_s[1])

This looks something like this if executed properly, and I've fallen in love with the info I get from this:

image.png.8d26e6b95d7e8c1e8898f73d643ca772.png

Now what I don't get is why this sleeping switches to the FG-process of Houdini. The python-script-TOP is set to evaluate In-Process, but when executing cleanly, it works in the BG nicely.

I'm grateful for any clue or alternative approach.

Thanks,
Martin

Edited by tortoise
Link to comment
Share on other sites

Woohoo! Managed to fix this by accident. And finally figured out how the python server works - kind of.

image.png.c1f71114a213ad8a5678d6f25d35b6a9.png

This is the setup and it fixes the issue completely. The gen_range detects the duration of the ticker from the settings on the HDA and the wait does a simple time.sleep() while the update_comment then does the fancy updating I want. Pretty much the same code as before with a few tweaks. :)  

I'll rename the topic so that it might be found by others having similar issues!

Cheers,
Martin

Edited by tortoise
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...