NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Difficulty releasing all TestStand references in Python

I'm doing some TestStand code in Python, to create some test cases based on Excel data. So I'm doing COM programming of both TestStand and Excel. It seems to be going well overall, but when the program exits, I am still getting a debug message about 2 PropertyObjects that aren't being released properly. I'm a bit stuck trying to track it down.

 

I've made some simplified code that demonstrates my issue. This is using Python 2.6. The file to run is TestStandDebug.py, and the other two are dependencies.

 

One further interesting little detail: There is a variable 'num_rows' which seems to influence whether or not the debug message appears. If it's big enough (100 on my PC, or 200 on a colleague's) then I get the debug message. If it's smaller, I don't.

 

(PS I couldn't attach .py files directly to this forum post--can this be changed?)

0 Kudos
Message 1 of 6
(4,787 Views)

Is Python a garbage collected language? If so, try forcing a garbage collection after all python references to TestStand objects are gone, except for a reference to the engine. Maybe the COM references need to be finalized so that they are actually released?

 

I'm completely guessing here, making an analogy with .net.

0 Kudos
Message 2 of 6
(4,786 Views)
Yes Python does garbage collection. However that's normally only needed
to find and clean up old objects with circular references. All objects
keep reference counts. As long as there are no circular references, when
an object has nothing left referring to it (e.g. variable name), then
the object gets destroyed. So in Python, variable names have to either
go out of scope (function exits) or the variable is explicitly deleted:

    del(ts_property_object)

 

I also just realised--my example requires a blank TestStand sequence
file with the name TestStandDebug.seq, so I should have included that in
the zip file.
0 Kudos
Message 3 of 6
(4,757 Views)
This is the dialog box I get when I run this on this Windows 2000 PC, with Excel 2003 and TestStand 4.2:
 
    ***********************************************************************************
    * TestStand Debug Options Warning
    * 
    * The Station Option, Report Object Leaks and Reported Known OS and
    * Component Problems, reported the following warnings on shutdown:
    * 
    *   *******************************************************************************
    *   * References to PropertyObjects were not released properly.
    *   *     Total number of objects: 2
    *   *     Number of top-level objects: 2
    *   * 
    *   *     Note: Some top-level objects may be included if they are referenced by
    *   *     an incorrectly released top-level object. For example, an unreleased
    *   *     SequenceContext object references a SequenceFile object.
    *   * 
    *   *     The following top-level objects were not released:
    *   * 
    *   *         PropertyObjects [1 object(s) not released]
    *   *             PropertyObject 0000001:
    *   *                 Type: ActiveX Reference
    *   *                 Value: Nothing
    *   * 
    *   * 
    *   *         And the following uncategoried objects:
    *   *             UIMessage (TEMessage)
    *   *******************************************************************************
    ***********************************************************************************

0 Kudos
Message 4 of 6
(4,756 Views)

I don't know what is causing the leaks, but I have a couple of comments:

 

1. I'm not very familiar with Python, but it appears that your code attempts to create the TestStand Engine, get a reference to a sequence file, unload the Engine and invoke methods on the sequence file. This generally will not work because you should not access TestStand objects after the Engine has been unloaded.

 

2. The UIMessage leak is curious because I have seen this occur when the application did not follow the recommended Engine shutdown steps (see "Shutting Down the Engine" help topic). These steps should not be necessary if you are just opening and closing sequence files unless the sequence files have load or unload callbacks and you don't pass the GetSeqFile_DoNotRunLoadCallback and ReleaseSeqFile_DoNotRunUnloadCallback options.

 

Message 5 of 6
(4,651 Views)

Thanks for the message, Erik.

 

As for comment (1), I think it's fine--I'm using Python "context managers" (functions marked with @contextmanager) to create the TestStand engine, and those are used in the 'with' statements. The 'with' statement runs the context manager up to the "yield" statement, and then the body of the 'with' runs. The remainder of the context manager (e.g. that shuts down the TestStand engine) executes after the 'with' body finishes.

 

As for comment (2), thank you for the pointers. I had not been doing the procedure described in "Shutting Down the Engine" help topic. My code was not doing any sequence execution, so in theory it should have been okay. I added the  GetSeqFile_DoNotRunLoadCallback and ReleaseSeqFile_DoNotRunUnloadCallback options as you recommended, but that didn't make a difference. But I added code to follow the procedure, calling Engine.ShutDown() and waiting for messages by polling, and my code now shuts down without the debugging message at the end.

 

So thanks for your help.

 

Regards,

Craig McQueen

0 Kudos
Message 6 of 6
(4,609 Views)