# Calling updatePixels() from a separate thread doesn't update the main window

**URL:** <https://discourse.processing.org/t/calling-updatepixels-from-a-separate-thread-doesnt-update-the-main-window/22696>\
**Category:** Processing.py\
**Created:** [July 17, 2020, 11:34pm UTC](https://discourse.processing.org/t/calling-updatepixels-from-a-separate-thread-doesnt-update-the-main-window/22696 "2020-07-17T23:34:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Underslash](https://avatars.discourse-cdn.com/v4/letter/u/ba8739/32.png) [@Underslash](https://discourse.processing.org/u/Underslash)\
**Post date:** [July 17, 2020, 11:34pm UTC](https://discourse.processing.org/t/calling-updatepixels-from-a-separate-thread-doesnt-update-the-main-window/22696/1 "2020-07-17T23:34:10Z")

</div>

Exactly what the title says, when I run updatePixels() from a function thats running in a thread, it doesn’t update the pixels, but calling updatePixels() from the function which I ran the thread from updates it. Example:

```auto
def func1():
    thread("func2()")
    time.sleep(2)
    updatePixels()

def func2():
    loadPixels()
    # do stuff with pixels
    ...
    updatePixels()

```

Where func2 takes more than 2 seconds to run, and when the program runs, it displays the loading partway through.

How can I get around this?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 17, 2020, 11:58pm UTC](https://discourse.processing.org/t/calling-updatepixels-from-a-separate-thread-doesnt-update-the-main-window/22696/2 "2020-07-17T23:58:24Z")

</div>

> [@Underslash](#):
>
> … from a function that’s running in a thread, it doesn’t update the pixels,

Sketch’s main canvas can’t be mutated outside its “Animation Thread”! 🧵

> [@Underslash](#):
>
> How can I get around this?

You can have a separate PGraphics for your thread and then render it on the “Animation Thread”: 💡

> **[PGraphics / Reference](https://processing.org/reference/PGraphics.html)**
>
> Main graphics and rendering context, as well as the base API implementation for processing "core". Use this class if you need to draw into an off-screen graphics buffer. A PGraphics object can be cons…

---

<div class="post-metadata">

**Author:** ![Underslash](https://avatars.discourse-cdn.com/v4/letter/u/ba8739/32.png) [@Underslash](https://discourse.processing.org/u/Underslash)\
**Post date:** [July 18, 2020, 1:10am UTC](https://discourse.processing.org/t/calling-updatepixels-from-a-separate-thread-doesnt-update-the-main-window/22696/3 "2020-07-18T01:10:37Z")

</div>

Ah, thanks for that, I’ll go check it out
