06-30-2023 09:31 AM
Hello all,
I'm trying to integrate a python class in teststand with the python adapter. But I'm struggling a bit, or maybe my understanding of how this works is wrong.
My python code contains a class which represents my dut and has several methods for testing (communication) and flashing it. I'm using the batchmodel with 16 sockets.
So I have a python step which creates an instance of this class and this is returned and saved in a fileglobal var (not shared) in teststand as an object ref. This object ref is passed to all python steps in teststand to make sure each socket is using its own instance of the class (this is working well).
How do I cleanup this instance, because the interpreter session keeps running? Is it enough to just put in teststand Fileglobals.Python_instanceRef = Nothing?
Why is the python interpreter session not closed between consequtive test runs to make sure no data is shared between them?
I tried to use an object ref to store the interpreter session ref, but this is not working...
Anyone has experience with this? Maybe I'm just not using it correctly...
Thanks in advance
07-07-2023 07:13 AM
Nick1991,
Context:
In Configure >> Adapters >> Python, you can configure 'Interpreter to Use' to execute the code modules. Interpreter session created for 'Global' has lifetime of TestStand application. Similarly interpreter session created for 'Per Execution' and 'Per Thread' has lifetime of TestStand Execution and Thread respectively. You can override the settings per Python step using the 'Advanced Settings' of the step. You can even create a new Python interpreter session and store it in a variable. Lifetime of the interpreter will be the lifetime of the variable which you can control.
Python objects stored in TestStand variable ensures that the lifetime of corresponding Python interpreter session is greater than the lifetime of the Python object stored in the variable.
Cleanup:
To destroy the interpreter session, you should do the following:
- Cleanup all the Python objects stored in TestStand variable. You can do it by setting 'Nothing' to the variable as you mentioned.
- If you have used Per Execution or Per Thread option, ensure corresponding Execution/Thread, for which interpreter session is created, is destroyed. You can do this by closing all execution window after completing the execution.
- If you are handling the lifetime of interpreter session by storing it in variable, clean it by setting its value to 'Nothing'
- If you are using 'Global' interpreter session, use File >> Unload All Modules to destroy the interpreter session.
-Shashidhar
10-16-2023 09:29 AM
Shashidhar,
Thanks for your reply, it helped me to understand the context. Still I have one situation where I can not get it to work.
If I configure the python steps individually to use an interpreter stored in an object ref in combination with a virtual environment, I get following error:
"Interpreter in the configured interpreter reference was created with settings different to the configured settings. Make sure the interpreter in the reference was created with same settings and retry."
With the "Python Virtual Environment" input box (step -> advanced settings) empty, this is working as expected.