# pvpython scripting in parallel

**URL:** https://discourse.paraview.org/t/pvpython-scripting-in-parallel/9210
**Category:** ParaView Support
**Created:** [March 17, 2022, 5:56pm UTC](https://discourse.paraview.org/t/pvpython-scripting-in-parallel/9210 "2022-03-17T17:56:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Ying](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/y/fbc32d/32.png) [@Ying](https://discourse.paraview.org/u/Ying)
#### Post date: [March 17, 2022, 5:56pm UTC](https://discourse.paraview.org/t/pvpython-scripting-in-parallel/9210/1 "2022-03-17T17:56:55Z")

</div>

Hi, I use **pvpython** scripting to convert a bunch of vtk files to png images in paraview.

The logic is to:  
(i) define main function **vtkToImg()**, which reads one vtk file and save it as one screenshot (.png);  
(ii) use **for-loop** to iteratively run the main function for all vtk files.

The script runs well for single core, but processing vtk file one by one is very time-cosuming. So I try to use **multi-processing** module to run the script in parallel, and the code looks like:

```auto
import multiprocessing as mp
from paraview.simple import *

def getvtkFile(path_vtk) # get vtk files in path_vtk           
      ...

def vtkToImg(vtkFile, path_img) # main function with 2 inputs
      ...

if __name__ == " __main__": # parallel

   path_vtk = './sequencedVTK/'
   path_img = './sequencedIMG/'
   
   # get vtk files
   vtkFiles = getvtkFile(path_vtk)

   # build pool including 8 processors
   pool = mp.Pool(8)
   pool.starmap(vtkToImage, [(vtkFiles[i], path_img) for i in range(len(vtkFiles))])  
   pool.close()

```

But when running this s in the terminal, I received the error _ **AttributeError: ‘Pool’ object has no attribute 'starmap’** _ I find this error appears due to I apply python2 instead of python3.

**So my question is:**  
**(1) how to apply python3 with pvpython?**  
**(2) is it reasonable to use multi-processing module for pvpython parallel? Or pvpython has other better methods to run in parallel?**

I would be very appreciated if anyone can give me some help!

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [March 18, 2022, 4:31pm UTC](https://discourse.paraview.org/t/pvpython-scripting-in-parallel/9210/2 "2022-03-18T16:31:46Z")

</div>

Hi @Ying ,

I’m afraid pvpython is not threadsafe and cannot be used like this.

You should either go higher with subprocesses, each importing paraview simple, or go lower and use pvbatch ([6. Remote and parallel visualization — ParaView Documentation 5.10.0 documentation](https://docs.paraview.org/en/latest/ReferenceManual/parallelDataVisualization.html))

Hth
