# Threading in a ParaView Python plugin (Linux)

**URL:** https://discourse.paraview.org/t/threading-in-a-paraview-python-plugin-linux/15888
**Category:** ParaView Support
**Tags:** python
**Created:** [December 20, 2024, 12:02pm UTC](https://discourse.paraview.org/t/threading-in-a-paraview-python-plugin-linux/15888 "2024-12-20T12:02:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![enricsosa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/enricsosa/32/13910_2.png) [@enricsosa](https://discourse.paraview.org/u/enricsosa)
#### Post date: [December 20, 2024, 12:02pm UTC](https://discourse.paraview.org/t/threading-in-a-paraview-python-plugin-linux/15888/1 "2024-12-20T12:02:19Z")

</div>

Hello,

I was trying to use the [threading](https://docs.python.org/3/library/threading.html) library in a python plugin, but it doesn’t work exactly as I want it to.

What I want is to create a thread that is always running continuously in the background, but currently I can’t get it to work. As an example and for simplicity, I’ll put a dummy case of a source module. With this code:

```auto
@smproxy.source(name="StorageDictReader", label="EnricSosa - StorageDict Reader")
class StorageDictReader(VTKPythonAlgorithmBase):
    def __init__ (self):
        VTKPythonAlgorithmBase. __init__ (self, nInputPorts=0, nOutputPorts=1, outputType='vtkPolyData')
        [...]
        self.dummy_thread = threading.Thread(target=self._dummy_thread_function, args=())
        self.dummy_thread.start()

    def _dummy_thread_function(self):
        print("[DUMMY THREAD] I'M A NEW DUMMY THREAD", flush=True)
        i = 1
        while True:
            print("[DUMMY THREAD] sleeping", i, "seconds", flush=True)
            sleep(1)
            i += 1

```

When I load the plugin and put the module in the pipeline, I see a print and that’s it. When I request “_RequestData_”, like pressing the “_Apply_” button or the “_Next Frame_” button for the next timestep, I also see prints from the thread, but it only runs for the time it takes for the plugin to “_RequestData_”. What I want is that the thread runs all the time, from the moment it starts with “_.start()_”. I don’t know if this is possible.

I hope I was understood. For additional information that might be useful, I am using Paraview 5.11.0 in a linux client-server environment. I have no rights to install and configure ParaView on the server. I have searched and saw this [Topic](https://discourse.paraview.org/t/running-a-script-in-the-background-vr-black-screen/3412), but it does not solve exactly what I want.

Best regards,  
Thanks in advance

---

<div class="post-metadata">

### Author: ![nicolas.vuaille](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nicolas.vuaille/32/5873_2.png) [@nicolas.vuaille](https://discourse.paraview.org/u/nicolas.vuaille)
#### Post date: [December 23, 2024, 2:10pm UTC](https://discourse.paraview.org/t/threading-in-a-paraview-python-plugin-linux/15888/2 "2024-12-23T14:10:20Z")

</div>

I do not really now about python threading, but if what you want is a source that has automatic refresh, see this thread: [update automatic data input](https://discourse.paraview.org/t/update-automatic-data-input/3222)

---

<div class="post-metadata">

### Author: ![enricsosa](https://discourse.paraview.org/user_avatar/discourse.paraview.org/enricsosa/32/13910_2.png) [@enricsosa](https://discourse.paraview.org/u/enricsosa)
#### Post date: [January 8, 2025, 1:14pm UTC](https://discourse.paraview.org/t/threading-in-a-paraview-python-plugin-linux/15888/3 "2025-01-08T13:14:14Z")

</div>

Hi @nicolas.vuaille , thanks for your help.

Sorry for my late reply, I posted this thread just before my holidays 😅.

As of now I was trying to avoid a `Live Programmable Source` because, for our case, a Python plugin is more handy. Anyways, I will try your proposed solution and let you know because it seems to be a good answer to update automatically.

Thanks.
