Adding Date via Python from csv - works fine in Viewport but can't be rendered - what's wrong? I try to add the Date from a .csv file as text in Blender 2.91 via Python.
It creates for each row a new Text and works fine in Viewport (one date per frame) but when I try to render this code as animation Blender crashes, if rendered as image it shows all Dates layered on each other:
import csv
import bpy

def render_stock(csv_path, start, start_frame):
    with open(csv_path) as stock_csv:
        stock_ob = csv.reader(stock_csv.read().splitlines())
     
    stock_header = []
    stock_data = []

    for v in stock_ob:
        if not stock_header:
            stock_header = v
        else:
            v = [(float(v[0])),
                 (float(v[1])),
                 (float(v[2])),
                 float(v[3]),
                 str(v[4]),
                 str(v[5])]
            stock_data.append(v)
            scale_factor = 0.3       


    frames = start_frame
    objs = []
    
    for counter in range(len(stock_data)):
        
        v = stock_data[counter]
        
    
        bpy.ops.object.text_add(location =(9,15,0.5), rotation =(1.7,0,-1.9))
        bpy.context.object.data.body = (v[5])
        
        
    def ani_handler(render):
        name = 'Text'
        objs = [obj for obj in render.objects.values() if name in obj.name]

        for i, obj in enumerate(objs):
            obj.hide_set(i != ((render.frame_current-1) % len(objs)))
    bpy.app.handlers.frame_change_pre.append(ani_handler)
        
    

render_stock('/&quot;filepath to&quot; .csv', (0, 0, 0), 0)
Thanks to batFINGER, the new code from this link:
blender.stackexchange.com/a/161107/15543
gives a workaround.
First step: Inserting the Dates from the csv file into a new text file named &quot;text&quot;.(by hand)
Second step: Putting the text_add line from above behind the csv loop with the text_body_handler as linked here. (run code and enjoy the Date in the rendering)
:)