NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to kill child threads spawned from a primary thread based on timeouts.Is there a way to kill a child thread from the primary thread in Test Stand?

How to kill an unresponsive child thread from a Parent thread based on timeouts in Teststand. Is there a way of killing any specific thread spearetely at all?
0 Kudos
Message 1 of 4
(5,300 Views)
Hello,

There is not a clear way to kill the execution of a TestStand thread from another thread (parent or otherwise); however, there is an "abort" method for executions. If you could put the code of your child thread into a new execution, you could then use the abort method to kill it.

Thank you for contacting National Instruments. I hope that this information helps. Take care!

Aaron B.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 4
(5,300 Views)
To sidj -
It is not clear as to whether the thread that you want to kill is a thread in a TestStand execution created using a Sequence Call step. I will assume yes.

In general killing threads within a process can make the process unstable because resources are not cleaned up properly, and events and message can be lost.

As long as a thread is "responsive", it is possible to have the thread periodically check for a condition to instruct it to exit.

Aaron suggested to launch the child thread as an execution because you can Terminate or Abort the child execution without affecting the parent execution.

For TestStand executions, a condition that can be checked is the execution's running state, i.e. Running, Terminating or Aborting. TestStand e
xecutions check for changes in this state automatically between the running of steps. In addition, many of the TestStand step types that block and wait also check for changes in the running state. If you own the code for a step's code module and it runs for a long period of time and the code module can monitor the execution's running state by passing it the Sequence Context, the step can be more responsive to a Terminate or Abort.

You can take a look at the code for the MessagePopup step type as a basic example.

Scott Richardson (NI)
Scott Richardson
https://testeract.com
Message 3 of 4
(5,300 Views)
Thanks Scott & Aaron for the replies.
Basically I had child threads hogging my hardware resource which needed to be used by others in the batch. I wanted to kill child threads (from the parent )which did not return within a stipulated time so that further tests could be run on the resource.
Now I have implemented this using new execution contexts instead of threads & it is working fine (with a terminate request from the primary sequence based on any timeout).
0 Kudos
Message 4 of 4
(5,300 Views)