How to setup a timer in a python script?

I’m trying to delay the execution of my code in a python script.

import unreal

timer_delegate = unreal.TimerDynamicDelegate()

def delayed_action():
    print('Do it!')

timer_delegate.bind_callable(delayed_action)

unreal.SystemLibrary.set_timer_delegate(timer_delegate, time=3, looping=False)

For some reason I get:

RuntimeWarning: SystemLibrary: No world was found for object (/Engine/Transiernt.TimerDynamicDelegate__PythonCallable_4) passed in to UEngine::GetWorldFromContextObject().

What’s the problem? Please, show a correct way to do it.

This aint the best approach but it works (This is for a forever loop).

This is my approach until I understand the python API properly:

import unreal
from threading import Timer

def hello():
    unreal.log_warning("Hello World")
    # Create a new timer that calls this function again after 5 seconds
    t = Timer(5.0, hello)
    t.start()

# Start the timer for the first time
hello()