Flow control to exit an event handler?

Is there a statement that can exit an event handler in the logic so I can use an if statement to selectively not execute the rest of the handler?

Not that I’m aware of.

However it should be possible to accomplish whatever you need to achieve using “if”, “elif” and “else” statements and possibly the “break” statement to exit loops when a condition is met.

If there are multiple factors deciding whether script should execute or not you may have to create “flag” variables and use those to determine the flow of the script.

Yes, you can use this:

import sys sys.exit(0)

This will gracefully stop a Vision module event handler script

1 Like

I use the sys.exit() statement in event handlers without any issues but it throws an error when used in an Extension Function, at least it does in the onCellEdited Extension function of a Power Table. Is there a similar statement that works in an Extension Function?

Use return.

1 Like

That works well, thank you.

Using Ignition 7.9.8 this approach does not work and still executes most of the script I am trying to avoid based on certain conditions…

import sys
if event.keyCode != event.VK_ENTER	:

bSuccess = False
username = ''
password = ''
userIP = ''

I am validating user login based on source IP and cannot have the full script being run every time.

Move your script to a function in a project script module. Have the event script simply call that function, passing the event as a function argument. Use return in the function to exit early.