It's likely a better idea to catch errors with a sound cue. You can do that via;
import time
import chime
chime.theme('mario')
chime.notify_exceptions()
def long_running_task():
for i in range(2):
time.sleep(1)
print(f"sleep {i + 1}")
print("done!")
raise ValueError("do I hear sound?")
chime.info()
long_running_task()