03-07-2018 05:18 PM
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.
Solved! Go to Solution.
03-07-2018 06:45 PM
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.
03-08-2018 03:39 AM - edited 03-08-2018 03:44 AM
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.
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.
03-08-2018 10:48 AM
Thanks for reading between the lines. This is exactly what I want to do!
03-16-2018 04:39 PM
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
?
03-19-2018 10:26 AM
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
?
03-19-2018 12:37 PM
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,
03-20-2018 05:31 AM
@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.
03-20-2018 11:14 AM
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?
03-20-2018 03:48 PM
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.