Alarm could not be acknowledged. It may no longer be registered

Run the script in the background. That is what system.util.invokeAsynchronous() is for. Scripts that run in the foreground should always be designed to run in a limited time, preferably less than 1/10 of a second. You might find the functions in later.py helpful, as described in this thread.