LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Python object refnum can only be used 2^20 times?

Solved!
Go to solution

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_test.png(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

 

 

error1744.png

 

 

 

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.

 

probe.png


If I manually close the old reference, error 1671 occurs in the next loop (‘testClass’ object has no attribute ‘count’).

close_reference.pngerror1671.png

 

 

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)

Download All
0 Kudos
Message 1 of 7
(667 Views)

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/Passing-Event-Refnum-to-Call-Library-Function/m-p/4107832/highlight...

 

https://forums.ni.com/t5/LabVIEW/Max-Queue-Number/m-p/3839884/highlight/true#M1086610

0 Kudos
Message 2 of 7
(618 Views)

What if you don't use the Shift register so you force it to use the 1st ref every time?

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 7
(604 Views)

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.

0 Kudos
Message 4 of 7
(580 Views)

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.

Message 5 of 7
(559 Views)

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.

 

 

force_first_ref.png

0 Kudos
Message 6 of 7
(515 Views)
Solution
Accepted by Hukahuka

This issue has been reported to LabVIEW R&D as Bug 2855444.

Message 7 of 7
(451 Views)