# Using invokeAsynchronous to run intensive query in background and showing data in a power table

**URL:** <https://forum.inductiveautomation.com/t/using-invokeasynchronous-to-run-intensive-query-in-background-and-showing-data-in-a-power-table/31244>\
**Category:** Ignition\
**Created:** [January 13, 2020, 10:35am UTC](https://forum.inductiveautomation.com/t/using-invokeasynchronous-to-run-intensive-query-in-background-and-showing-data-in-a-power-table/31244 "2020-01-13T10:35:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnmichael.savio](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@johnmichael.savio](https://forum.inductiveautomation.com/u/johnmichael.savio)\
**Post date:** [January 13, 2020, 10:35am UTC](https://forum.inductiveautomation.com/t/using-invokeasynchronous-to-run-intensive-query-in-background-and-showing-data-in-a-power-table/31244/1 "2020-01-13T10:35:32Z")

</div>

Hi,  
I have a need here where data from a remote database is fetched through an API, and that data is then displayed in a power table. while doing so, the script executes for a long time. Lets say 30 seconds, during that time the client freezes over, i understand the reason why, hence to work around that I’m trying to use invokeAsynchronous and invokeLater functions, but still the issue remains.

```auto

```

Anyway, It would really help if someone can support me with this.  
thanks,  
John

Edit: This was sorted out, hence the script was removed. If anyone requires help/ the scripting for this reply back in this thread.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 13, 2020, 1:08pm UTC](https://forum.inductiveautomation.com/t/using-invokeasynchronous-to-run-intensive-query-in-background-and-showing-data-in-a-power-table/31244/2 "2020-01-13T13:08:30Z")

</div>

Please edit your post to place triple backquotes (these: ```) on a line above and again on a line below your script so it formats properly.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [January 13, 2020, 1:33pm UTC](https://forum.inductiveautomation.com/t/using-invokeasynchronous-to-run-intensive-query-in-background-and-showing-data-in-a-power-table/31244/3 "2020-01-13T13:33:22Z")

</div>

When you call `system.util.invokeAsyncrhonous(tagfetch)`, and have a parameter `param`, you really need to set it to something in the function call as you can’t do it in the `system.util.invokeAsynchronous` call, so something like `def tagfetch(param = someOtherDefinedVariable):`

Also, when you try

`for x in response` I don’t see where `response` was defined? So currently it looks like that would do nothing.

Also, please appropriately indent your code, python lives and dies by indents so reading what you have its hard to tell whats inside the function and whats inside the main extension function.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 13, 2020, 10:35pm UTC](https://forum.inductiveautomation.com/t/using-invokeasynchronous-to-run-intensive-query-in-background-and-showing-data-in-a-power-table/31244/5 "2020-01-13T22:35:02Z")

</div>

As posted, the incorrect indentation of control structures and the missing data flow make your script indecipherable. Please post the entire real script, anonymizing where needed instead of cutting.

---

<div class="post-metadata">

**Author:** ![johnmichael.savio](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@johnmichael.savio](https://forum.inductiveautomation.com/u/johnmichael.savio)\
**Post date:** [January 14, 2020, 3:58am UTC](https://forum.inductiveautomation.com/t/using-invokeasynchronous-to-run-intensive-query-in-background-and-showing-data-in-a-power-table/31244/6 "2020-01-14T03:58:30Z")

</div>

I have posted the entire script as used, with proper formatting. hope it helps.

---

<div class="post-metadata">

**Author:** ![johnmichael.savio](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@johnmichael.savio](https://forum.inductiveautomation.com/u/johnmichael.savio)\
**Post date:** [January 14, 2020, 3:59am UTC](https://forum.inductiveautomation.com/t/using-invokeasynchronous-to-run-intensive-query-in-background-and-showing-data-in-a-power-table/31244/7 "2020-01-14T03:59:41Z")

</div>

As I said earlier, that was just an edited version of the code. you could refer the one that I recently updated. My point being, the function works properly, I just need it to get executed asynchronously, in a parallel thread.

---

<div class="post-metadata">

**Author:** ![johnmichael.savio](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@johnmichael.savio](https://forum.inductiveautomation.com/u/johnmichael.savio)\
**Post date:** [January 14, 2020, 7:28am UTC](https://forum.inductiveautomation.com/t/using-invokeasynchronous-to-run-intensive-query-in-background-and-showing-data-in-a-power-table/31244/8 "2020-01-14T07:28:36Z")

</div>

@pturmel I have figured it out. Thanks for the help anyway.
