10-23-2024 11:39 PM
When using a Python Node with a Python object refnum as input, it works fine for 1,048,576 calls, but on the 1,048,577th call, error 1744 occurs.
Is there any way to avoid this error and continue using the Python object refnum?
(LabVIEW code)
(Python code)
class testClass():
def __init__(self):
self.count = 0
def count_up(self):
self.count+=1
def create_object():
return testClass()
def count_up(obj:testClass):
obj.count_up()
return obj.count
When I check the Python object refnum with a probe, its value seems to change before and after the Python Node. In other words, it seems that a new reference is being created continuously without closing the original reference.
If I manually close the old reference, error 1671 occurs in the next loop (‘testClass’ object has no attribute ‘count’).
By the way, it is possible to execute more than 1,048,577 calls by holding the Python object as a global variable on the Python side instead of using the Python object refnum in LabVIEW. However, this does not resolve the underlying issue with the Python object refnum.
(Translated from Japanese)
Solved! Go to Solution.
10-24-2024 02:42 AM
It's the same for Queues, notifiers and such (For any specific datatype).
There is a "magic cookie" counter for managing all of these references int he background in LabVIEW. I ran into this error with Queues in the past and got "out of memory" errors even though my program was using very little RAM.
https://forums.ni.com/t5/LabVIEW/Max-Queue-Number/m-p/3839884/highlight/true#M1086610
10-24-2024 03:14 AM
What if you don't use the Shift register so you force it to use the 1st ref every time?
10-24-2024 06:38 AM
I suppose Python is not doing anything with the reference to force LabVIEW to create a new reference?
The allocation of a new reference for each call of what is (assumedly) a pass-through to a Python function seems like it might be a bug.
10-24-2024 09:39 AM - edited 10-24-2024 09:43 AM
I can observe the same behavior.
Last time I tried to integrate python code within LabVIEW, I encountered a similar issue:
One of my python nodes created an object at the beginning, which I passed to 2 parallel "processing" tasks.
Since a new object reference was created at every call to my processing functions, the 2 tasks did not operate on the same object anymore, it was like a copy.
I could not find documentation telling whether the python objects in LabVIEW are expected to be passed by reference or by value (despite the wire type being "Python Object Refnum").
So I ended up using a DVR to read the object ref, do the python call and finally write the new ref... quite impractical.
It indeed seems like a bug.
Regards,
Raphaël.
10-25-2024 12:32 AM
When I try to continue using the reference created before the loop, error 1671 occurs during the second Python Node.
It seems that the reference used in the first Python Node becomes invalid, and I need to use the reference from the output side instead.
10-25-2024 01:25 PM
This issue has been reported to LabVIEW R&D as Bug 2855444.