# Get user confirmation in python without blocking thread

**URL:** <https://forum.inductiveautomation.com/t/get-user-confirmation-in-python-without-blocking-thread/54089>\
**Category:** Ignition Early Access\
**Created:** [December 14, 2021, 8:53am UTC](https://forum.inductiveautomation.com/t/get-user-confirmation-in-python-without-blocking-thread/54089 "2021-12-14T08:53:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [December 14, 2021, 8:53am UTC](https://forum.inductiveautomation.com/t/get-user-confirmation-in-python-without-blocking-thread/54089/1 "2021-12-14T08:53:49Z")

</div>

Hello,

I want in my script get a confirmation from user for running some code so I wonder as perspective is single thread per session how can I open a popup and wait until the user click on cancel or confirm and base on that I run my code?  
In vision it is very easy with system.util functions.

I think may be I have to pass my code as function to popup and in popup it run the function base on user action.  
Is any there any other solutions for this?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [December 14, 2021, 9:01am UTC](https://forum.inductiveautomation.com/t/get-user-confirmation-in-python-without-blocking-thread/54089/2 "2021-12-14T09:01:20Z")

</div>

If you make it a modal, the gui being single threaded shouldn’t be an issue, I think ?  
Or is there something else that gets blocked and that must keep running ?

I’m guessing you could use messages to make a more generic version of an `action` popup, with the message handler configured on the button/whatever opens the popup, and passing it the message handler’s name as parameter… Then you can have two buttons on that popup, one that closes it and the other one that sends the message.

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [December 14, 2021, 9:20am UTC](https://forum.inductiveautomation.com/t/get-user-confirmation-in-python-without-blocking-thread/54089/3 "2021-12-14T09:20:33Z")

</div>

The problem of message is the view that call the popup has many instances in the primary view so for each Lister I have to have a different msg type which is not possible since the msg type is hard coded in perspective.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [December 14, 2021, 9:22am UTC](https://forum.inductiveautomation.com/t/get-user-confirmation-in-python-without-blocking-thread/54089/4 "2021-12-14T09:22:41Z")

</div>

Perspective components have the java.lang.Object.wait() and notify functions .  
I think it makes them pauze the thread untill something else notifies it… i have never used it tho so im not sure it will do what you want

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [December 14, 2021, 9:24am UTC](https://forum.inductiveautomation.com/t/get-user-confirmation-in-python-without-blocking-thread/54089/5 "2021-12-14T09:24:45Z")

</div>

Maybe you could differentiate between them using the payload ?

---

<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:** [December 14, 2021, 11:03am UTC](https://forum.inductiveautomation.com/t/get-user-confirmation-in-python-without-blocking-thread/54089/6 "2021-12-14T11:03:35Z")

</div>

Perspective is not single thread per session. I don’t know of any way to wait for action on a popup, though.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 14, 2021, 5:48pm UTC](https://forum.inductiveautomation.com/t/get-user-confirmation-in-python-without-blocking-thread/54089/7 "2021-12-14T17:48:03Z")

</div>

> [@victordcq](#):
>
> Perspective components have the java.lang.Object.wait() and notify functions .

Even from Java code, you should basically never call `wait()` or `notify()`. I would definitely not do it from scripting.

I strongly suspect the only real way out here is rearchitecting; perhaps message handlers reacting to each 'stage' in this process accordingly. There's no way to do 'blocking' work like this in scripting.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [December 14, 2021, 6:30pm UTC](https://forum.inductiveautomation.com/t/get-user-confirmation-in-python-without-blocking-thread/54089/8 "2021-12-14T18:30:29Z")

</div>

I do this similar to your last comment.

> [@nader.chinichian](#):
>
> I think may be I have to pass my code as function to popup and in popup it run the function base on user action.  
> Is any there any other solutions for this?

I handle all my code through project scripts, and then will essentially call a universal popup that is provided a callback function, and on submit it calls back the same function with keyword arguments for response data. This way I can call the same function multiple times in a row and the second time I know just to skip to the response code because a response is present.

I use this pretty heavily in an app that requires a ton of dynamic user confirmations and inputs.

Technically this doesn’t “wait” for the popup, it just splits the code into two executions of “the first half” and the “back half” in the same function.

EDIT: I actually also use this to cancel currently running threads as well, a bit more complicated to explain, but that’s possible as well.
