# Cancelling Running Loop

**URL:** <https://forum.inductiveautomation.com/t/cancelling-running-loop/44528>\
**Category:** Ignition\
**Created:** [March 16, 2021, 3:30pm UTC](https://forum.inductiveautomation.com/t/cancelling-running-loop/44528 "2021-03-16T15:30:51Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 16, 2021, 3:51pm UTC](https://forum.inductiveautomation.com/t/cancelling-running-loop/44528/2 "2021-03-16T15:51:01Z")

</div>

> [@kghali](#):
>
> While running a for loop in the vision script, ignition freezes for a couple of minutes

This is bad programming. Event scripts run on the single GUI thread and **must** execute very quickly. A tenth of a second or less is a good, long-standing rule of thumb. If you have a script that is expected to take longer, particularly anything that includes a request across the network, you should use system.util.invokeAsynchronous() to place it in its own thread. There are restrictions on what such a background thread can do, though. You might find this topic helpful:

> [@Update GUI via Asynchronous thread](http://forum.inductiveautomation.com/t/update-gui-via-asynchronous-thread/9666):
>
> I’ve got a script I am experimenting with that can take a lot of time to execute, so I now use the system.util.invokeAsynchronous to run the script in a separate thread to keep the GUI from locking up. I am using the asynchronous thread to copy files from one place to another, and I would like to show the progress of the file copy with a progress bar. How would I go about this? I am importing a few python libraries to do this. import shutil def fileTransfer(): path = system.file.openFile() …

---

_[View the full topic](https://forum.inductiveautomation.com/t/cancelling-running-loop/44528)._
