# Designer hanging with script, but client runs fine

**URL:** <https://forum.inductiveautomation.com/t/designer-hanging-with-script-but-client-runs-fine/58006>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [April 4, 2022, 3:40pm UTC](https://forum.inductiveautomation.com/t/designer-hanging-with-script-but-client-runs-fine/58006 "2022-04-04T15:40:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacob\_Sanchez](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@Jacob\_Sanchez](https://forum.inductiveautomation.com/u/Jacob_Sanchez)\
**Post date:** [April 4, 2022, 3:40pm UTC](https://forum.inductiveautomation.com/t/designer-hanging-with-script-but-client-runs-fine/58006/1 "2022-04-04T15:40:55Z")

</div>

The following (section) of a script i’m working on will run fine (doesn’t hang) running as a client, but when running it in the designer, designer hangs indefinitely if the print statement commented bellow is not here. I’ve tried replacing it with sleep() and it still hangs. I’m not sure why it’s working with the print statement there but not when it is gone.

What i am doing is writing the time to a text box that is inside a template instance. If i write to the text property of a text box which is not inside a template, it does not hang. This was working fine at one point but i made some changes to the template (which i cannot seem to figure out what exactly did this) now it hangs.

```auto
				for component in container.components:
					componentName = tagName + '_' + alarmName
					if(component.name == componentName):
						for component in component.components:
							if(component.name == 'SnoozeControls'):
								for component in component.components:
									if(component.name == 'SnoozeStatus'):
										print('*') # If this print statement is not here, designer hangs
										component.text = str(hrTime)

```

---

<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:** [April 4, 2022, 3:43pm UTC](https://forum.inductiveautomation.com/t/designer-hanging-with-script-but-client-runs-fine/58006/2 "2022-04-04T15:43:39Z")

</div>

You are using `component` as your loop variable in all of the nested loop. I would not expect it to ever work correctly.

---

<div class="post-metadata">

**Author:** ![Jacob\_Sanchez](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@Jacob\_Sanchez](https://forum.inductiveautomation.com/u/Jacob_Sanchez)\
**Post date:** [April 4, 2022, 3:51pm UTC](https://forum.inductiveautomation.com/t/designer-hanging-with-script-but-client-runs-fine/58006/3 "2022-04-04T15:51:59Z")

</div>

I was being a bit lazy there, i have made them unique, still having the same issue. I did just notice that it the script doesn’t hang if i stay in the script editor, as soon as i switch over to the vision window that is when it hangs.

```auto
				for component in container.components:
					componentName = tagName + '_' + alarmName
					if(component.name == componentName):
						for component1 in component.components:
							if(component1.name == 'SnoozeControls'):
								for component2 in component1.components:
									if(component2.name == 'SnoozeStatus'):
										print('*')
										component2.text = str(hrTime)

```

---

<div class="post-metadata">

**Author:** ![Jacob\_Sanchez](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@Jacob\_Sanchez](https://forum.inductiveautomation.com/u/Jacob_Sanchez)\
**Post date:** [April 4, 2022, 4:12pm UTC](https://forum.inductiveautomation.com/t/designer-hanging-with-script-but-client-runs-fine/58006/5 "2022-04-04T16:12:47Z")

</div>

Here is the entire function, which runs every 1 second.

```auto
def handleAlarms(shutdown=0):
	from datetime import timedelta
	# This function should be ran periodically from client to handle our snoozed alarms
	alarmBasePath = '[default]Powerhouse_PLC/Alarms/'
	path = '[default]Powerhouse_PLC/Alarms/ProjectMemoryTags/SnoozeTime/'
	results = system.tag.browse(path = '[default]Powerhouse_PLC/Alarms/ProjectMemoryTags/SnoozeTime/', filter = {})
	container = system.gui.getWindow('main').rootContainer
	
	# itterate tags listed in path, checking each ones expire uptime, and then un-snoozing if expireTime < system uptime
	for result in results.getResults():
		path = str(result['fullPath'])
		snoozeTagName = str(result['name'])
		expireUptime = system.tag.read(path).value
		currentUptime = system.tag.read("[System]Gateway/UptimeSeconds").value

		if(expireUptime != 0):

			alarm = snoozeTagName.split("_")
			tagName = alarm[0]
			alarmName = alarm[1]
			
			if(expireUptime <= currentUptime or shutdown == 1):

				print(snoozeTagName + " Alarm Snooze Expired, un-snoozing now")
				setAlarmSnooze(tagName, alarmName, 0)
			else:
				snoozeSecondsRemaining = expireUptime - currentUptime
				hrTime = timedelta(seconds=snoozeSecondsRemaining)	

				for component in container.components:
					componentName = tagName + '_' + alarmName
					if(component.name == componentName):
						for component1 in component.components:
							if(component1.name == 'SnoozeControls'):
								for component2 in component1.components:
									if(component2.name == 'SnoozeStatus'):
										print('*')
										component2.text = str(hrTime)
										
		if(expireUptime == 0):
			alarm = snoozeTagName.split("_")
			tagName = alarm[0]
			alarmName = alarm[1]
			container = system.gui.getWindow('main').rootContainer
						
			for component in container.components:
				if('template' in str(type(component))):
					componentName = tagName + '_' + alarmName
					if(component.name == componentName):
						for component1 in component.components:
							for component in component1.components:
								if(component1.name == 'SnoozeStatus'):
									if(component1.text != 'Not Snoozed'):
										component1.text = 'Not Snoozed'
										

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 4, 2022, 4:23pm UTC](https://forum.inductiveautomation.com/t/designer-hanging-with-script-but-client-runs-fine/58006/6 "2022-04-04T16:23:47Z")

</div>

Same issue, you are using component multiple times in nested loops at the bottom of your script.

---

<div class="post-metadata">

**Author:** ![Jacob\_Sanchez](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@Jacob\_Sanchez](https://forum.inductiveautomation.com/u/Jacob_Sanchez)\
**Post date:** [April 4, 2022, 4:26pm UTC](https://forum.inductiveautomation.com/t/designer-hanging-with-script-but-client-runs-fine/58006/7 "2022-04-04T16:26:48Z")

</div>

I will fix that, but at this time that part of the script is not running. I just found that i run the script via a button it does not hang, only when run via client timer script.

---

<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:** [April 4, 2022, 4:28pm UTC](https://forum.inductiveautomation.com/t/designer-hanging-with-script-but-client-runs-fine/58006/8 "2022-04-04T16:28:46Z")

</div>

You are also using `system.tag.browse()` in the foreground. Like any other script function that calls out to the gateway, it should be called in a background script, and UI interaction handled with `.invokeLater()`. See this topic:

> [@Update GUI via Asynchronous thread](https://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() …

I make an exception for button actionPerformed scripts (short ones), as an operator can expect some processing delay upon their command.
