NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Using python's multithreading module in python adapter step

Solved!
Go to solution

Is using python's multithreading module in a TestStand python adapter step supported? This step's code works fine in python but hangs when called from from TestStand.

 

I've attached a simple example to demonstrate.

 

TS2022q4, python 3.10

 

Possible alternatives: use TS to do the threading or use a call executable step.

Download All
0 Kudos
Message 1 of 3
(1,304 Views)
Solution
Accepted by topic author stephenb2

stephenb2,

You can use `multiprocessing` module in any function/class called from TestStand's Python adapter. Before creating instance of `Process`, you need to use `multiprocessing.set_executable` by pointing to the python exe you want to use for multiprocess.

 

Reason: TestStand executes Python modules in an external process which embeds CPython interpreter. By default, `multiprocessing` module uses `sys.executable` which will be the path of current executable (which is the process shipped along with TestStand). TestStand's executable is designed to work only when called from TestStand. If using `multiprocessing` module, you will be calling TestStand's executable from Python which does not work since the parameters are not understood by the exe. Hence, in your code, explicitly mention the Python executable to be used for multiprocessing.

 

Note: We do have plans to for improving the behavior where multiprocessing works out of the box.

 

-Shashidhar

Message 2 of 3
(1,291 Views)

Thanks so much for the explanation. Calling out the path of the current python executable works as you described.

0 Kudos
Message 3 of 3
(1,269 Views)