3
$\begingroup$

I have this script here (Please ignore the code quality):

from datetime import datetime
from bpy.app import handlers

TIMER = None
TOTAL_RENDER_TIMES = []
TOTAL_TIME = 0;
rendertime=None
rendertimeFLOAT=None
def start_timer(scene):
    global TIMER
    TIMER = datetime.now()

def elapsed(dummy):
    rendertime=datetime.now() - TIMER
    rendertimeFLOAT=rendertime.total_seconds()
    TOTAL_RENDER_TIMES.append(rendertimeFLOAT)
    print(TOTAL_RENDER_TIMES)
    #print("Elapsed:", datetime.now() - TIMER)
def complete():
    for x in TOTAL_RENDER_TIMES:
        TOTAL_TIME+=x

    print("TOTAL RENDER TIME: "+TOTAL_TIME)
    print("AVERAGE TIME PER FRAME: "+(TOTAL_TIME/len(TOTAL_RENDER_TIMES)))
handlers.render_pre.append(start_timer)
handlers.render_stats.append(elapsed)

It's supposed to get the render time of each frame and return the total time, and average time. But when I run it, the console tells me this:

Traceback (most recent call last): File "\Text", line 14, in elapsed NameError: name 'renderTimeFLOAT' is not defined Traceback (most recent call last): File "\Text", line 15, in elapsed NameError: name 'renderTimeFLOAT' is not defined

My problem, though, is that I fixed the error on lines 14 and 15. After some experimentation, I found that the script completely didn't update! It was still running an old version of the script. I have tried saving the text, making a new file, running the script, to no avail. I can go as far as to delete everything in the editor and it will still function. What's going on!??! Currently running Blender 3.0 Portable

$\endgroup$

1 Answer 1

4
$\begingroup$

When you run the script, it creates a handler and appends it to the list of handlers. When you run the script again, it creates a new handler and appends it, but the old handler is still there.

You can check the contents of the handler list in the console, eg.

>>> bpy.app.handlers.render_pre

It will still have the handler function from all your script runs.

You can clear out the previous handlers by putting something like this at the top of your script

# This will clear all handlers (including any you didn't make)
handlers.render_pre.clear()
handlers.render_stats.clear()

# Alternatively, you can try to clear out just the ones
# from your last script run
if handlers.render_pre:
    if handlers.render_pre[-1].__name__ == "start_timer":
        handlers.render_pre.pop()
if handlers.render_stats:
    if handlers.render_stats[-1].__name__ == "elapsed":
        handlers.render_stats.pop()

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .