Script Console print() not working

One of my other devs brought me a odd issue. After upgrading to 8.1.10 print statements when using script console for debugging stopped working. This only happens in specific situations where a custom class is used in the script, it almost seems as though the print() is being overridden somehow. However this issue did not occur in 8.1.6, so I assume this is related to the update to jython 2.7.2

I cannot find any obvious issues, any jython experts know of changes in 2.7.2 that could cause this?

Print statements or print calls as a function? The latter would require from __future__ import print_function as the first line in whatever execution environment youā€™re in, on any Python 2.X version.

2 Likes

Sorry my bad lingo, print statements

Here is an exampleā€¦ where you see the print statement stops working after executing a function.

Iā€™d send you the code, but way to many dependencies on our specific environment in this code, so just trying to find some help looking for a direction to investigate.

Could the code be calling System.exit() or otherwise exiting ā€˜too fastā€™? I donā€™t think you can non-trivially break the print statement (outside of the aforementioned magic import to turn it into a function).

If you can annotate the code youā€™re calling with more prints, that may help identify where in the code itā€™s ā€œstoppingā€.

I can replicate this issue. In the attached screenshot I ran the script console twice. The first time nothing got printed after the class method was run and the second time all the prints came through fine. Every time I open a new designer this issue happens on the first execution. I am on version 8.1.10

Can either of you provide an SSCCE that demonstrates the problem?

I am running into a similar issue on 8.1.11, but on the Output Console.

This is the code on actionPerformed on a button:

from __future__ import print_function

print("Hello world!")

But when I comment the import, I get the output for all previous clicks plus the last one, at once.

Summoning @PGriffith.

Could this be flagged as a bug and fixed on 8.1.12?

CC: @cmallonee

Iā€™ve been out for a week, but letā€™s get into it :slight_smile:
Thereā€™s pretty much no chance this is going to be fixed in 8.1.12; itā€™s too late in the game.

You posted a minimal example a few days ago, but that seems like a different issue than the main topic of this thread. Itā€™s potentially a bug worth fixing (Iā€™ll take a look at it) but without an SSCCE for the main issue I donā€™t have a lot to go forward with.

Iā€™m still trying to put together a SSCCE for you on the primary issue, just havenā€™t been able to carve a few hours out to do itā€¦ :frowning:

1 Like

This doesn't work 'right' because the future import print_function isn't flushing the output stream for whatever reason.

Iā€™ve also discovered this issue but I didnā€™t find a correlation between custom classes and the issue. 8.1.10

We used some logger functions though out the function weā€™re calling and the logs do post, but not the print statements or the return of the function.

It seems like the console output is just being dropped or truncated some how.

A second execute in the script console shows the expected output on the interpreter.

Hi PGriffith, I'm running in the same problem: the print() function (with use of _ _ future _ _ module) appears as no flushing the output stream (wrapper.log, print () used inside a timer script). If I remove the module _ _ future _ _ import and using print without (), it works. Quite strangely, if a second script is flushing on the wrapper, all is ok also with print(). The same script, in the Designer script console, properly works always. I wish to maintain the _ _ future _ _ module. Is there anything I can do? Many thanks.

The error was with Jython, but looks to be fixed in the latest patch release, so when we next update Jython in Ignition it'll be fixed:

2 Likes

Hi, many thanks for the information. It would be great to have a stand-alone "patch" for existing version, not feasible to update production environment for that.

That's not really how things work. Jython is tightly integrated throughout Ignition, so when we bump the version we have to regression test all of Ignition, which we also do with every product version.

If you, personally, want to take the significantly more risky step of dropping in a new version of Jython to fix this minor issue, you can do so - just download the Jython release jar from Github into the gateway, in the lib/core/common folder, overwriting the existing Jython JAR. But be aware it's totally unsupported.

2 Likes