09-08-2022 10:24 AM
The meaning of error -2147417842 is "The application called an interface that was marshalled for a different thread."
I use TS 2021 SP1 and Python 3.8
Below are the actions which trig the issue :
- In a step type, I have an edit substep which calls a python code which displays a popup window and allows to configure a property of the step. In the edit menu of a step of this type, I execute successfully this code
- Then I execute my sequence. At the first step which calls a python module, the error occurs. I noticed that the error occurs only if the step displays a popup window or has the TestStand sequenceContext as input of the python module. Otherwise the step execution is ok
If I leave and reopen TestStand and do the same 2 actions above in the opposite order (1. execution, 2. edit), then the edit action raises the same error
I read information about STA and MTA which seems to explain this behaviour. But I'm not familiar with these concepts and that doesn't give me a soluton
What I don't understand is that when the edit action is completed, the thread which executes the edit action should be removed from memory when I unload all modules. But it doesn't.
Does anybody has a solution or a workaround (other than leaving and reopening TestStand) ?
Thanks
Laurent
09-09-2022 06:47 AM
Laurent,
I need more information to reproduce. Which UI framework are you using in Python. Can you share any simple example which you are using for the edit substep?
Without knowing much about the issue, I can specify only one workaround.
My workaround ensures that you use a different Python interpreter session for edit time and runtime scenario. Since none of the data is shared across Python interpreter session, I am guessing that you will not get the issue.
Do the following for the workaround:
- For edit substep, in the step settings dialog, launch advanced settings dialog.
- Disable 'Use Adapter Settings'.
- In the advanced settings, specify the version of Python to use for edit substep.
- Set 'Python Interpreter to Use' to be 'Object Reference'. Ensure that 'Interpreter Reference' expression is empty and 'Create Interpreter if it does not exist' enabled.
- Click OK and save the details.
Now, everytime you click the edit button, edit substep will execute in a new interpreter session.
The only disadvantage is that, there will no longer be one location to modify the Python version. In future, if you need to modify the version, you need to do it in both adapter settings and in the advanced settings of the edit substep.
-Shashidhar
09-13-2022 09:33 AM
Hi Shashidhar,
Here is my code for the edit step :
import tkinter as tk
from tkinter import ttk
...
def popup_selection_bin(failed_bin: bool, ts_context) -> None:
# debug
ctypes.windll.user32.MessageBoxW(None, "Process name: niPythonHost.exe and Process ID: " + str(getpid()), "Attach debugger", 0)
and the call from the Edit substep of the step type
As the popup message is not displayed when I click on the edit menu, I guess the popup_selection_bin is not executed.
I tried your workaround but I have the same error message at edit time
Below is my configuration of the Python adapter
As I said previously, the error occur only if I display a python popup window at runtime
Regards
Laurent
10-03-2022 04:07 AM
Hi Shashidhar,
I made some further attempts to make your workaround work, with different Python versions, or with a new version of pythonnet (as my edit function call a .net assembly)
It has always been unsuccessful
Can you please share your code if it is possible, so I can try to make it work on my PC
Thanks for your help
Regards
Laurent