From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Python Node - Python Error During While Loop Prevents Subsequent Code Executions

The problem occurs when I am attempting to run a Python Node in my while loop. When I pass in the correct input (an image file path) into the Python Script via the Labview Python Node, everything works fine; python executes, returns my image, and the while loop repeats.

 

If I do not input a correct file path, the Python script returns an error, as expected. However, the issue arises when, with the while loop still running, I re-enter a correct image file path. The Python Script does not attempt to run again with the new file path. It appears that the Python Script simply stops executing once it encounters its first error.

 

What I would like to happen is that the Python Script would continue to run as normal for the next loop, and ignore the previous error. 

 

What I've tried so far is to add an error handling to my Python script, where if the image can not be found, it would execute a sys.exit() line of code, ending the code. However, the Python Node in Labview still reads the sys.exit() as an error, and consequently stops running during the next loop.

 

Is there a simple way to solve this issue?

 

UPDATE: It appears that the Python Script still continues to execute in the next loop even if there was an error. However, it appears that it will only do this for about ~15 loops before completely exiting the Python Script and refusing to run again until rebooted. Need to prevent the Python script for quitting.

 

Attached is code.

Download All
0 Kudos
Message 1 of 4
(1,472 Views)

(Sorry, just stabbing in the dark. I am sure an expert will chime in)

 

  • Is there anything happening in the missing subVI?
  • If you look at the memory use in task manager, does it constantly increase?
  • Does the image file constantly change? (Why else would you need to re-read it every second?)
  • I probably would use a path control for the path and use "path to string" before wiring to the node. This ensures that the path is well formed, independent of OS.
0 Kudos
Message 2 of 4
(1,464 Views)

Thanks for your reply.

 

I've attached the missing VI. IT simply takes a 3-axis image and converts it into a displayable 2D image and IMAQ image. The other missing one (one below) is simply for measuring the loop speed and can be removed.

 

  • If you look at the memory use in task manager, does it constantly increase?

The memory does not change.

 

  • Does the image file constantly change? (Why else would you need to re-read it every second?)

In this example, it is the same image. However, this is just a test code. In my actual code, it would be getting a new image file path every run.

 

  • I probably would use a path control for the path and use "path to string" before wiring to the node. This ensures that the path is well formed, independent of OS.

Good note. I've made that change.

 

 

My main question is why Python is refusing to run in future iterations after passing an error? My guess would be some sort of timeout in Python where if it keeps returning errors after a given time (or number of runs), it simply gives up and exits the module all together.

0 Kudos
Message 3 of 4
(1,435 Views)

This issue has been fixed in LabVIEW 2023 Q3.


Christina Rogers
Principal Product Owner, LabVIEW R&D
0 Kudos
Message 4 of 4
(534 Views)