# 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:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kghali](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@kghali](https://forum.inductiveautomation.com/u/kghali)\
**Post date:** [March 16, 2021, 3:30pm UTC](https://forum.inductiveautomation.com/t/cancelling-running-loop/44528/1 "2021-03-16T15:30:51Z")

</div>

This is not the first time this happens. While running a for loop in the vision script, ignition freezes for a couple of minutes then shows a read timeout error. The problem is that the system shows that the loop is still running and the memory trend starts to fill out. I closed the designer and reopened it and it showed me that there is another user editing the same program, when I try to find that user and detect the overlap, it shows my name as the “other user”. The memory keeps filling up even after restarting designer and the user doesn’t really close!

Is there a way to abort all threads in a software?

---

<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() …

---

<div class="post-metadata">

**Author:** ![kghali](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@kghali](https://forum.inductiveautomation.com/u/kghali)\
**Post date:** [March 16, 2021, 4:09pm UTC](https://forum.inductiveautomation.com/t/cancelling-running-loop/44528/3 "2021-03-16T16:09:43Z")

</div>

Thank you, however, I was running one of the manual examples with some minor modifications:

server = “Ignition OPC UA Server”  
device = ‘[’+event.source.parent.getComponent(‘PLC OPC Name Text’).text+’]’  
folderpath = ‘Devices/’+device  
tags = system.opc.browse(opcServer=server, folderPath=folderpath)

for row in tags:  
print row.getDisplayName()

We have many programs for each device and I wanted to see what names will it show.

---

<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, 4:16pm UTC](https://forum.inductiveautomation.com/t/cancelling-running-loop/44528/4 "2021-03-16T16:16:04Z")

</div>

OPC browse is notorious for long execution times. And in a Vision client, involves a network callout to the gateway. Not safe to run in a button event. Don’t do it.

---

<div class="post-metadata">

**Author:** ![kghali](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@kghali](https://forum.inductiveautomation.com/u/kghali)\
**Post date:** [March 16, 2021, 4:17pm UTC](https://forum.inductiveautomation.com/t/cancelling-running-loop/44528/5 "2021-03-16T16:17:50Z")

</div>

I can tell. Thanks again
