Force Close Startup Script

I have a startup script that checks for valid IPs in a dataset and closes the application if "access is denied." I've got an error box via system.gui.errorBox() to alert the user, but I want this box to stay on the screen for a time (or until the user closes it) before exiting the application via system.util.exit().

I've tried

from time import sleep

time.sleep(3)

between the errorBox and exit calls, but I always get a global name "time" not defined error

Is there another way I can do this?

Should this be tagged "Vision"?

1 Like

Well, your script isn't working right now because you're saying from time import sleep and then attempting to call time.sleep. If you want to call it as time.sleep, then just import time. If you're using from time import sleep, then you should just call it as sleep(3).

That gets the sleep function working, but now my errorbox is blank as it sleeps

Yeah, because you're calling sleep on the event dispatch thread, which is going to disrupt all painting operations.

You need to use system.util.invokeAsynchronous to kick off a 'background' thread to do this waiting and closing operation.

Something like:

def waitAndExit():
    from time import sleep
    sleep(3)
    system.util.exit()

system.gui.errorBox("", "")
system.util.invokeAsynchronous(waitAndExit)

EDIT:
invokeLater probably works too:

system.gui.errorBox("", "")
system.util.invokeLater(system.util.exit, 3000)
1 Like

Perfect! Thanks