# Show a message after a function completes, without having the user wait for it to complete

**URL:** <https://forum.djangoproject.com/t/show-a-message-after-a-function-completes-without-having-the-user-wait-for-it-to-complete/7450>\
**Category:** Using Django\
**Created:** [April 9, 2021, 1:45pm UTC](https://forum.djangoproject.com/t/show-a-message-after-a-function-completes-without-having-the-user-wait-for-it-to-complete/7450 "2021-04-09T13:45:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jakobhenningjensen](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jakobhenningjensen/32/3751_2.png) [@Jakobhenningjensen](https://forum.djangoproject.com/u/Jakobhenningjensen)\
**Post date:** [April 9, 2021, 1:45pm UTC](https://forum.djangoproject.com/t/show-a-message-after-a-function-completes-without-having-the-user-wait-for-it-to-complete/7450/1 "2021-04-09T13:45:04Z")

</div>

Say I have this view:

```python
import threading

def MyView(request):

    thr = threading.Thread(target=my_func, args=(request,)) 
    thr.start()#Runs a function that the user should not wait for
    return render(request, "my_site")

```

where

```python

def my_func(request):
    #Some function that takes 10 second and the user should not wait for this
    sleep(10)
    messages.success(request, "Your meal is ready!") 
    return render(request, "my_other_site")

```

What I want to do is; I have a function of which the user should not wait for to complete i.e they should be able to continue browsing, and then when the function is done, I want to show them a message either using `messages` or a pop-up box or something third.

Is there a way to do that in Django directly (since it all runs synchronous I can’t think of a way), or what would be the most optimal way ?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 9, 2021, 1:58pm UTC](https://forum.djangoproject.com/t/show-a-message-after-a-function-completes-without-having-the-user-wait-for-it-to-complete/7450/2 "2021-04-09T13:58:38Z")

</div>

Correct, there’s not.

There’s not even going to be an indirect way of doing it unless you construct your entire app as an SPA, or add some JavaScript to every page to check the server for notifications.

Keep in mind that every new page removes/replaces \_everything from the old page, including any JavaScript that may have been running. So if you render a complete new page, you’ll need to reload some JavaScript to issue a request to the server to see if there are any notifications to be processed. (If they’re going to be on one page for a while, you could use a polling mechanism to see if there are new notifications to be handled while they’re staying on that page.)

---

<div class="post-metadata">

**Author:** ![Jakobhenningjensen](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jakobhenningjensen/32/3751_2.png) [@Jakobhenningjensen](https://forum.djangoproject.com/u/Jakobhenningjensen)\
**Post date:** [April 9, 2021, 2:03pm UTC](https://forum.djangoproject.com/t/show-a-message-after-a-function-completes-without-having-the-user-wait-for-it-to-complete/7450/3 "2021-04-09T14:03:27Z")

</div>

Yeah, thats what I thought as well… /:

---

<div class="post-metadata">

**Author:** ![Jakobhenningjensen](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jakobhenningjensen/32/3751_2.png) [@Jakobhenningjensen](https://forum.djangoproject.com/u/Jakobhenningjensen)\
**Post date:** [April 9, 2021, 2:12pm UTC](https://forum.djangoproject.com/t/show-a-message-after-a-function-completes-without-having-the-user-wait-for-it-to-complete/7450/4 "2021-04-09T14:12:09Z")

</div>

But its gonna pe a performance issue I would assume, if I each second need to a server to get new requests

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 9, 2021, 2:15pm UTC](https://forum.djangoproject.com/t/show-a-message-after-a-function-completes-without-having-the-user-wait-for-it-to-complete/7450/5 "2021-04-09T14:15:39Z")

</div>

Really depends upon how many concurrent users you’re expecting - and being realistic about that estimate.  
A couple hundred users probably wouldn’t be much sweat - and keep in mind that the polling only needs to occur when someone is sitting on a page and not browsing to other pages. If they’re actively browsing, they’re generating _far_ more load on the server than if they’re just sitting and reading.
