Gateway event occasionally error when execute Project libary script : NameError: name is not defined

I have created a script in my project libaray, and I am executing it in my Gateway Event - Timer, so that the script runs every second.
Usually, it works well, but there are occasional errors says the name is not defined.
But the Function name is defined well like mentioned, it only has error occasionally, like 5-10 times 24 hours.

The script itself is fairly simple, involving some calculations.

And this issue is not just for one Gateway event, quite a few report similar errors.
I suspect this related to gateway event timer frequency, but no idea how this can be improved.

Is the project in question being edited frequently? Or one of the projects it inherits from? If so, it may be a script library race condition I reported recently, and you should also report to IA support. (It is hard to reproduce--your case may help.)

No, this project isn't frequently edited, and some errors occur at midnight when no one is actively editing the project.
While this project does inherit from another, but the running script is actually present within the current project itself.
I will report to IA support , thanks.

Doesn't matter. Edits on the other will cause the current project's scripts to restart.

The inherited project is not frequently edited either, still thanks for bring this up , I keep this in mind.

I've had a problem like this before. I'm not sure if it's the same thing here, but it would be worth a check.

If you can safely call this script from the Script Console, then your script is compiling and this isn't the solution to your issue.

If it is a compile error, a common culprit is spacing. It doesn't matter if you use tabs or spaces, so long as you're consistent. I'd recommend turning on whitespace characters when looking through the script to find invisible errors. To see them, right-click in the script editor to find the setting.
image

Once it's selected, you'll see tabs as arrows and spaces as tiny dots:
image

This can help you find errors that would otherwise be easy to miss:
image

I upgraded my Ignition to 8.1.42 recommended by IG support and issue resolved.