0
$\begingroup$

Is it possible to get total render time via Python code when render’s done? enter image description here

$\endgroup$
1
$\begingroup$

Render Handlers

Borrowing heavilly from Is it possible to get render time per tile?

Test code prints the total time elapsed from render init handler being fired, to render complete (or cancel)

from datetime import datetime
from bpy.app import handlers

FRAME_START_TIME = None
RENDER_START_TIME = None

def handler_function(name):
    def handler(scene):
        print(name)
    return handler

frame_handlers = [getattr(handlers, name)
        for name in dir(handlers) if name.startswith("render_")]

def add_dummy_handlers():
    for  handler in frame_handlers:
        handler.append(handler_function(name))   

def clear_handlers():
    for  handler in frame_handlers:
        handler.clear()

def render_init(scene):
    global RENDER_START_TIME
    RENDER_START_TIME = datetime.now()  
    print("Render Start")  

def render_pre(scene):
    global FRAME_START_TIME
    FRAME_START_TIME = datetime.now()

def render_stats(dummy):
    print("Elapsed:", datetime.now() - FRAME_START_TIME)

def complete(scene):
    print("Total:",  datetime.now() - RENDER_START_TIME)

def cancel(scene):
    print("CANCELLED.... After:",  datetime.now() - FRAME_START_TIME)

clear_handlers()

handlers.render_init.append(render_init)
#handlers.render_pre.append(render_pre)
#handlers.render_stats.append(render_stats) # write or post ?
handlers.render_complete.append(complete)
handlers.render_cancel.append(cancel)

Output of a 4 frame render animation.

Render Start
Saved: '/tmp/0000.png'
 Time: 00:01.06 (Saving: 00:00.48)

Saved: '/tmp/0001.png'
 Time: 00:00.92 (Saving: 00:00.26)

Saved: '/tmp/0002.png'
 Time: 00:00.87 (Saving: 00:00.25)

Saved: '/tmp/0003.png'
 Time: 00:00.97 (Saving: 00:00.32)

Total: 0:00:03.846082

Added code from https://blender.stackexchange.com/a/62870/15543 to clear the handers clear_handers(), and also to add a set of dummy handlers that simply print their name when called. add_dummy_handlers()

$\endgroup$
  • $\begingroup$ Wow! That's complicated... I'll try this out, thanks. $\endgroup$ – SagRU Mar 1 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.