# Debug Console not showing 'Live' Outputs

**URL:** <https://forum.inductiveautomation.com/t/debug-console-not-showing-live-outputs/54503>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [December 28, 2021, 6:21pm UTC](https://forum.inductiveautomation.com/t/debug-console-not-showing-live-outputs/54503 "2021-12-28T18:21:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [December 28, 2021, 6:21pm UTC](https://forum.inductiveautomation.com/t/debug-console-not-showing-live-outputs/54503/1 "2021-12-28T18:21:27Z")

</div>

Running Ignition Edge 8.1.11:  
I am running a button-triggered script with a for-loop which reads hundreds (at times, thousands) of values from a remote OPC server, and writes the values of tags to a memory array tag. I noticed that my intermediate “print” statements (status of read commands, timestamp, etc.) do not display in the Output Console until AFTER the script is completed. However, if I execute the same script from within the Script Console, I see the outputs immediately. For sake of convenience, I’ve generated some sample code utilizing a sleep() function in order to reproduce my issue:

```auto
from time import sleep
timeStart = system.date.now()
i=0
for i in range (10):
	sleep(1)
	timeNow = system.date.now()
	print system.date.millisBetween(timeStart, timeNow)
print "Complete"

```

When executed in button script, I do not see the 1s increments in the Output Console until after the full 10 sec has elapsed.  
However, if this code is executed in the Script Console, I am able to see the 1s intermediate print commands as they are printed.  
Modification to the above code which produces results ‘should’ also migrate to my code easily. Any insight as to how to view ‘live’ Console Outputs is much appreciated.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 28, 2021, 6:44pm UTC](https://forum.inductiveautomation.com/t/debug-console-not-showing-live-outputs/54503/2 "2021-12-28T18:44:55Z")

</div>

I’m guessing the debug output console just can’t update until your script is done blocking the UI thread. If it’s long running and does a bunch of blocking operations you should probably figure something else out, even if that’s just running it async and trying to keep additional button presses from happening while it runs.

---

<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:** [December 28, 2021, 6:54pm UTC](https://forum.inductiveautomation.com/t/debug-console-not-showing-live-outputs/54503/3 "2021-12-28T18:54:03Z")

</div>

Use `system.util.invokeAsynchronous()` to run the function in the background and use a logger from `system.util.getLogger()` instead of print.

And absolutely do _ **not** _ call any component methods from that background thread. More information here:

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

---

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [December 28, 2021, 11:18pm UTC](https://forum.inductiveautomation.com/t/debug-console-not-showing-live-outputs/54503/4 "2021-12-28T23:18:34Z")

</div>

Thanks for the tips! And, also for bearing with me (always in training…)  
I initially experimented with invokeAsynchronous(), but obviously had a fundamental misunderstanding of how to implement. The link provided (along with a few others, below) helped with some fundamentals:  
[DOC81/Project+Library](https://docs.inductiveautomation.com/display/DOC81/Project+Library)  
[DOC81/User+Defined+Functions](https://docs.inductiveautomation.com/display/DOC81/User+Defined+Functions)  
[DOC81/Component+Methods](https://docs.inductiveautomation.com/display/DOC81/Custom+Component+Methods)

In my example provided, I was able to prevent the UI from locking up (and able to see updates in the Output Console during execution) by creating a script called “myFuncs” in the Project Library w/ the following:

```auto
def runProg():
	from time import sleep
	timeStart = system.date.now()
	i=0
	for i in range (10):
		sleep(1)
		timeNow = system.date.now()
		logger = system.util.getLogger("myFuncsLogger")
		logger.info(str(system.date.millisBetween(timeStart, timeNow)))
	logger.info("Complete")

```

Then, actionPerformed button script was updated to contain:

```auto
system.util.invokeAsynchronous(myFuncs.runProg)

```

Output Console is updating as expected. Not withstanding my limited ‘application-specific info’, let me know if you would recommend to execute any of the above any differently.  
Re: my original task, I’m now passing relevant variables to the function, and working on preventing additional button presses during execution of prior button-press. Cheers!

---

<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:** [December 28, 2021, 11:24pm UTC](https://forum.inductiveautomation.com/t/debug-console-not-showing-live-outputs/54503/5 "2021-12-28T23:24:56Z")

</div>

Do avoid any form of `sleep()` in production code. Technically permitted in asynch threads (including Perspective events), but generally implies a patch over a race condition.

I recommend, in the button’s `actionPerformed` method, before lauching the background thread, that you set the button’s enable to false. At the end of the background thread, preferably in a `finally` clause, you use `.invokeLater()` to turn it back on.

{ also, get the logger instance once, not in every loop. }

---

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [December 28, 2021, 11:37pm UTC](https://forum.inductiveautomation.com/t/debug-console-not-showing-live-outputs/54503/6 "2021-12-28T23:37:00Z")

</div>

> Do avoid any form of `sleep()` in production code.

Agreed. Actual code is using system.opc.readValue() & system.tag.writeBlocking().

> I recommend, in the button’s `actionPerformed` method, before lauching the background thread, that you set the button’s enable to false. At the end of the background thread, preferably in a `finally` clause, you use `.invokeLater()` to turn it back on.
> 
> { also, get the logger instance once, not in every loop. }

Great insight as to my oversight. Much appreciated!
