LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to check if a Vi clone is still running such that we can interrupt it

Solved!
Go to solution

Hi all,

 

I am performing an sqlite3 database query using a 3rd party wrapper library. Sometimes, the query can last 7-10 seconds. This causes our software to freeze until the query returns.

 

I've been able to call a function which takes the database reference and interrupts it based on a timer loop. I've included the example here, with a timeout defined as 2000ms.

 

This would normally go and interrupt the query if it takes more than 2 seconds to execute. This works fine. However, if the query terminates early, I'd like to stop the timer to interrupt, otherwise, it might go and interrupt other sql queries that may be running.

 

I would normally use the VI reference for the sql_exec function and check if it is running, but it is reentrant and will likely be running another instance during the 2 second timer.

0 Kudos
Message 1 of 11
(3,156 Views)

There is a property VI Clone name that is unique for each clone instance.  

 

In cases like this I would use a named Notifier and send Clone name and state from the clone to whomever cares to watch the clone state.


"Should be" isn't "Is" -Jay
Message 2 of 11
(3,136 Views)
Solution
Accepted by topic author DT1981

This doesn't answer your question at all, but I don't see how your question is related to the story and code you've posted. If you have clones that you are calling from diagrams (not by reference) there is no way to stop them (except by stopping the entire hierarchy). I think what you want is to stop the parallel while loop when the query finishes normally.

 

You could lose the entire while loop and openG VI's. Simply use an event structure.

 

So you put the sqlite ref into the event structure. Add a timeout event, set it to the time you want. Put the sqlite3_interrupt in it. When the sequence ends normally, send a value signaling to a control. In the value change event of the control, do nothing.

SQLite timeout.png 

BTW: the Boolean ref was added by the snippet tool... You can simply statically link to the Boolean, and in the attached VI.

 

BTW2: Completely untested. I don't have SQLite.

Message 3 of 11
(3,107 Views)

Thanks for reading between the lines. This is exactly what I want to do!

0 Kudos
Message 4 of 11
(3,084 Views)

Hello,

 

I've now implemented this in my program and there is one issue.

 

What I observe is that this vi will wait until the timeout to actually get out of the VI. What would be a way to have this VI exit if either:

- database read is fast enough

- timed out and we called a database interrupt which caused the database read to end and the VI exits

?

0 Kudos
Message 5 of 11
(3,051 Views)

Hello,

 

I've now implemented this in my program and there is one issue.

 

What I observe is that this vi will wait until the timeout to actually get out of the VI. What would be a way to have this VI exit if either:

- database read is fast enough

- timed out and we called a database interrupt which caused the database read to end and the VI exits

?

0 Kudos
Message 6 of 11
(3,026 Views)

DT1981,

 

An option that comes to my mind is using a User Generated Event with your event structure. That way, you would end the execution when:

a) the timeout happens

b) you get a user event

 

 

Warm regards,

0 Kudos
Message 7 of 11
(3,016 Views)

@DT1981 wrote:

Hello,

 

I've now implemented this in my program and there is one issue.

 

What I observe is that this vi will wait until the timeout to actually get out of the VI. What would be a way to have this VI exit if either:

- database read is fast enough

- timed out and we called a database interrupt which caused the database read to end and the VI exits

?


The value signaling Boolean should do that. A user event would to he exact same thing, but takes more work.

 

In other words, there is something wrong in either the VI I uploaded, or in your implementation of it.

0 Kudos
Message 8 of 11
(2,997 Views)

Please let me know if I understand correctly.

 

The boolean refnum negates itself once the database read vi finishes, and we have the event handler catch the Boolean refnum's value change event and exit the event handler?

0 Kudos
Message 9 of 11
(2,979 Views)

Before you spend too much time on interrupting a long query, have you ensured you have made the query as short as possible?   Do you have indexes on box.boxorderid and boxdata.camid?   Have you run ANALYZE? The query you show (pulling a small amount of data out of a large table) is exactly the kind where the right index can turn seconds into milliseconds.

0 Kudos
Message 10 of 11
(2,970 Views)