12-17-2009 04:55 PM
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?)
12-17-2009 05:00 PM
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.
12-19-2009 04:00 AM
12-19-2009 04:01 AM
01-04-2010 09:34 AM
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.
01-06-2010 04:55 PM
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