# Force Close Startup Script

**URL:** <https://forum.inductiveautomation.com/t/force-close-startup-script/78175>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [August 21, 2023, 6:46pm UTC](https://forum.inductiveautomation.com/t/force-close-startup-script/78175 "2023-08-21T18:46:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [August 21, 2023, 6:46pm UTC](https://forum.inductiveautomation.com/t/force-close-startup-script/78175/1 "2023-08-21T18:46:15Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 21, 2023, 6:47pm UTC](https://forum.inductiveautomation.com/t/force-close-startup-script/78175/2 "2023-08-21T18:47:50Z")

</div>

Should this be tagged "Vision"?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 21, 2023, 7:08pm UTC](https://forum.inductiveautomation.com/t/force-close-startup-script/78175/3 "2023-08-21T19:08:54Z")

</div>

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)`.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [August 21, 2023, 7:10pm UTC](https://forum.inductiveautomation.com/t/force-close-startup-script/78175/4 "2023-08-21T19:10:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 21, 2023, 7:13pm UTC](https://forum.inductiveautomation.com/t/force-close-startup-script/78175/5 "2023-08-21T19:13:38Z")

</div>

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:

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

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

```

EDIT:  
`invokeLater` probably works too:

```auto
system.gui.errorBox("", "")
system.util.invokeLater(system.util.exit, 3000)

```

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [August 21, 2023, 7:24pm UTC](https://forum.inductiveautomation.com/t/force-close-startup-script/78175/6 "2023-08-21T19:24:17Z")

</div>

Perfect! Thanks
